New object with HQL

I think that the section 15.6. The select clause covers what you’re trying to achieve: 15.6. The select clause … Queries can return multiple objects and/or properties as an array of type Object[]: select mother, offspr, from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr Or as a … Read more

UnsupportedOperationException: The application must supply JDBC connections

Wow, just fixed the problem. sessionFactory = configuration.buildSessionFactory(new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry()); I was missing the .applySettings(configuration.getProperties()) Learnings configure() should be called AFTER setProperty Use hibernate.connection.url and NOT connection.url if you use hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect Set log4j property for hibernate logs to ALL, so that you can see more detailed issues To get rid of the WARN Recognized obsolete hibernate … Read more

Hibernate IN Clause with multiple columns

Putting down here how I implemented this. Basically we need to make a Hibernate Component (read @Embeddable object) out of the set of columns we need to query on and embed it in the main Entity. The group of columns can be combined as below: @Embeddable public class CompositeColumns{ private String col1; private String col2; … Read more

createEntityManager throws java.lang.NullPointerException at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus

If you’re using Hibernate 4 and trying to create a EntityManagerFactory manually (or SessionFactory) declared as <jta-datasource>, there is a property you must set on your persistence.xml called hibernate.transaction.jta.platform. For using on JBoss 7 <property name=”hibernate.transaction.jta.platform” value=”org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform” /> I found about this property at Hibernate Docs

Should Hibernate be able to handle overlapping foreign keys?

There is a way to bypass the validation and get it to work, thus indicating the column is a “@JoinColumnsOrFormulas” then put the solution: Error: @ManyToOne @JoinColumns(value = { @JoinColumn(name = “country_code”, referencedColumnName = “country_code”), @JoinColumn(name = “zip_code”, referencedColumnName = “code”)}) private Zip zip = null; @ManyToOne @JoinColumns(value = { @JoinColumn(name = “country_code”, referencedColumnName = … Read more

In Spring with jpa/hibernate, how do I keep a session open to avoid lazy initialization exceptions? Basically, you have a few options. -You can use the “open session in view” pattern where you use a filter/interceptor/AOP – style logic to open a session when server side logic begins, and close it when it’s through. -You could implement conversations spanning several request-response cycles. A plain old Servlet Filter is the easiest.

Hibernate without Primary Key

Hibernate requires that entity tables have primary keys. End of story. 50k records is simply not that many when you’re talking about a database. My advice: add an autoincrement integer PK column to the table. You’ll be surprised at how fast it is.