How to map one class to different tables using hibernate/jpa annotations

Using @MappedSuperclass, you would proceed as follows: @MappedSuperclass public class Transaction … @Entity @Table(name=”tbl_creditcard_approved_txns”) public class DeclinedTransaction extends Transaction … @Entity @Table(name=”tbl_creditcard_declined_txns”) public class ApprovedTransaction extends Transaction … Use @AttributeOverride to override column names between the two types of Transaction objects, if needed. Update: I see that you want to map one @Entity to two … Read more

How to auto detect entities in JPA 2.0

You need add to the persistence.xml the next line: <exclude-unlisted-classes>false</exclude-unlisted-classes> e.g. <?xml version=”1.0″ encoding=”UTF-8″?> <persistence version=”2.0″ …> <persistence-unit name=”YourPU” …> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name=”eclipselink.logging.level” value=”ALL”/> <property name=”eclipselink.ddl-generation” value=”drop-and-create-tables”/> </properties> </persistence-unit> </persistence>

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

FetchMode join makes no difference for ManyToMany relations in spring JPA repositories

Going through many forums and blogs to read for your problem (I guess you might have done that before posting it here) I too think that @Fetch(FetchMode.JOIN) will be ignored if you use the Query interface (e.g.: session.createQuery()) but it will be properly used if you use the Criteria interface. This is practically a bug … Read more

LazyInitializationException in JPA and Hibernate

Thanks to Shailendra I started to look closely at the transaction and noticed that the transaction was never starting. With that information I did some investigation and found this: Spring @Transaction not starting transactions. I put <tx:annotation-driven/> in my servlet-context.xml file and suddenly the transaction for logDOI started up and everything worked correctly; I no … Read more

JPA Native Query set null parameter

I have faced the same issue when use EntityManager.createNamedQuery(guess the same issue with createNativeQuery). In case you are going to pass nullable parameter to Query then use TypedParameterValue which allows to pass the type. For instance: setParameter(“paramName”, new TypedParameterValue(StandardBasicTypes.LONG, paramValue)); Here you explicitly set the type of passed value and when you pass null value … Read more