hibernate

Help me to write an sql-statement to do something like this

You can also write hibernate hql or criteria queries. I have Teacher entity and Student entity like this : class Teacher { public Long id ; public Set<Student> students; } class Student { public Long id ; public Teacher teacher ; public Boolean passedSemester1; public Boolean passedSemester2; } You can ...

using Hibernate to loading 20K products, modifying the entity and updating to db

I am using hibernate to update 20K products in my database. As of now I am pulling in the 20K products, looping through them and modifying some properties and then updating the database. so: load products foreach products session begintransaction productDao.MakePersistant(p); session commit(); As of now things are pretty s...

Having an issue with org.hibernate.SessionException: Session is closed! in Hibernate

I've done quite a bit a research on this with no luck, but all the answers have a tendency to point toward the session context settings in the config file. What is odd is that I get a session connection the very first time I hit the page (and therefore, a successful result set), but then when I reload I get the following exception: org.h...

What is the basic pattern for using (N)Hibernate?

I'm creating a simple Windows Forms application with NHibernate and I'm a bit confused about how I'm supposed to use it. To quote the manual: ISession (NHibernate.ISession) A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps an ADO.NET connection. Factory for ...

Effective Entity Update In Hibernate ?

How can I update an entity "effectively" in hibernate just as by using SQL. For example : I have a Product entity, which has a field name createTime. When I use session.saveOrUpdate(product) I have to get this field from database and then set to product then update, actually whenever I use session.saveOrUpdate(), I updated ALL fields, ...

Invalidating JPA EntityManager session

A project I am working on uses Spring 2.5 & JPA with Hibernate as a provider. My DAO classes extend JpaDaoSupport, so I get my JpaTemplate using the getJpaTemplate() method. The back-end database can get changed either by my application, or a third-party application. When a third-party application changes the database (mostly config...

Hibernate/Spring: Persisting collections

Hi guys, I've got two objects: User and Permission, where User has a Collection. In my "create" service, I read a bunch of Permissions, put them in a HashSet, add them to the user, and create the user using my DAO that says ((SessionFactory) sessionFactory).getCurrentSession().save(user); When I look in my object, all looks fine, bu...

Passing JDBC url from Maven to hibernate.cfg.xml

I have a hibernate.cfg.xml with the JDBC Url configured thus: <property name="hibernate.connection.url">jdbc:mysql://${server.hostname}:3306/dsm?zeroDateTimeBehavior=convertToNull&amp;jdbcCompliantTruncation=true&amp;autoReconnect=true</property> Those & are required (instead of just &) in order to avoid the exception: The reference t...

Hibernate and stored procedures

As my understanding on setting hibernate, I need to create table meta data file (person.hbm.xml), include all the fields mapping java object (person.java) If we use stored procedures for all transaction, do we still need the above configuration? It seems hibernate and stored procedures will overlap, We set up the stored procedur...

Hibernate - how to map an EnumSet

Hi all, I've a Color Enum public enum color { GREEN, WHITE, RED } and I have MyEntity that contains it. public class MyEntity { private Set<Color> colors; ... I already have a UserType to map my Enums. Do you know how to map a Set of Enums in the Hibernate hbm.xml? Do I need a UserType or there's an easiest way? Thanks ed...

hibernate's transaction read and subsequent update

Hi I have situation in which I read a record from a database. And if everything is ok I'll modify few properties and commit transaction. But in situations two threads do the same, they will update the same record. How to make it in hibernate? ...

Collection.contains(Enum.Value) in HQL?

I'm a little confused about how to do something in HQL. So let's say I have a class Foo that I'm persisting in hibernate. It contains a set of enum values, like so: public class Foo { @CollectionOfElements private Set<Bar> barSet = new HashSet<Bar>(); //getters and setters here ... } and public enum Bar { A, B }...

Can Hibernate automatically uppercase a column on read/insert via configuration?

We have some columns with data that must always be in uppercase to ensure uniqueness. I was wondering if hibernate can force all such columns to uppercase via some configuration file change? We actually use a custom UserType for encrypting/decrypting column data for some other table, but I figured that would be overkill just to upperca...

[Grails] HibernateException: No session currently bound to execution context

I'm trying to create a very basic REST-ish web service with Grails and Postgres. I have the read() & delete() methods working, but I can't get create() to work. Hibernate just gripes, "HibernateException: No session currently bound to execution context." Here's my create method: def create = { def member = new Member(params) member....

hibernate query cache specify cache duration

below is how i do query cache getHibernateTemplate().setCacheQueries(true); List<IssSection> result = (List<IssSection>) getHibernateTemplate().findByCriteria(crit); getHibernateTemplate().setCacheQueries(false); may i know how to specify duration of maximum time to cache this method? let say i want to clear cache after 5 min...

[Java] How should I unit test Spring, Hibernate and Struts using junit

What is the best practice? How should I implement it so that the database isn't polluted? ...

Getting my webapp to be database agnostic with Hibernate...

So the ultimate in scope-creep came in the other day: since we're using Hibernate, could we make our webapp run on Oracle as well as MySQL, interchangably? I thought this would be a simple case of changing hibernate.cfg.xml so that instead of explicity stating MySQL-specific options, it would reference a JNDI datasource, allowing the ap...

Using Hibernate Validator with JPA and Spring

I'm using Hibernate Validator 4.0.2, Spring 3.0 and Hibernate 3.3.2 (which, as I understand it, is pre-JPA2) as a JPA 1 provider. I've found it easy to integrate the Validator into the MVC layer (it just works) but can't see how to integrate the validator automatically into the JPA entityManager (JPA 1). Basically, I have some entities...

Hibernate - Avoiding unnecessary join when using foreign key in where clause

Hi I try to optimize the database queries in Hibernate, but I found a blocker: <class name="SupportedLanguageVO" table="AR_SUPPORTED_LANG" > <cache usage="read-only"/> <id name="Id" type="java.math.BigInteger"> <column name="ID" sql-type="NUMBER(20)" not-null="true"/> <generator class="assigned"/> </id> <property name="Ord...

Hibernate best approach for one Java class and multiple tables?

Put another way: How do you model/map a heavily reused child class/table to many different parent entities? I have several entity types each being persisted into its own table: class A --> table A class B --> table B .... Now I need to make each of these classes the parent of a 1:M unidirectional child collection. The collection is a...