Hello,
I have an application in the following runtime env stack: Hibernate 5.2.2 (JPA 2.1), Spring 4.3.2, Java 8 (1.8.0_102), Weblogic 12.1.3 application server, Oracle 11 db.
I tried compile time instrumentation of my Hibernate persistence classes as indicated in (
https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#BytecodeEnhancement) using hibernate-enhance-maven-plugin and setting :
Code:
<failOnError>true</failOnError>
<enableLazyInitialization>true</enableLazyInitialization>
I build the logic by specifying among the other goals: org.hibernate.orm.tooling:hibernate-enhance-maven-plugin:enhance. At Maven build time the goal is executed and it indicates in the console output that my Hibernate configured classes are successfully instrumented.
However at runtime I have 2 issues:
1 - the persistent entity attributes annotated with @Id are null, following an Hibernate a HQL NamedQuery execution. This entity is only queried through Hibernate. The CUD is done outside the application.
2 - for an entities hierarchy (superclass marked as @Inheritance(strategy = InheritanceType.SINGLE_TABLE)) only the superclass gets instrumented. The subclasses don't get instrumented, I checked with a Java decompiler(the setters/getters are not replaced with the interceptor calls). However at Maven build, when it executes the enhance goal, it displays that these subclasses were successfully instrumented.
Some more details about entity configuration from point 1: there is a superclass-subclasses hierarchy using @Inheritance(strategy = InheritanceType.SINGLE_TABLE))
Code:
@NamedQueries({
@NamedQuery(name = MyAbstractClass.myQuery, query = "select b " + "from MyAbstractClass b "
+ "where b.id1 = :" + Params.id1 + " order by b.aDate"),
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ID1", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorOptions(force=true)
@Table(name = "MY_TABLE")
public abstract class MyAbstractClass {
public static final String myQuery = "MyAbstractClass.myQuery";
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID1")
private Long id1;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID2")
private Long id2;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID3")
private Long id3;
@Temporal(TemporalType.DATE)
@Column(name = "A_DATE")
private Date aDate;
@Column(name = "A_STRING")
private String aString;
@Column(name="A_NUMBER")
private Long nNumber
//getters and setters for all properties above.
}
Each class is also annotated (@Entity, @Immutable, @DiscriminatorValue("123456") ) and it adds some other simple attributes (String,Boolean annotated with @Column).
When I run the MyAbstractClass.myQuery the returned entity has all populated attributes except the id1, id2, id3 which contain null. I checked in the db and it is not true. Moreover the query is based on id1 (see where clause).
I tried removing @GeneratedValue(strategy = GenerationType.IDENTITY) but nothing changes
Am I missing something / doing something wrong?
Is it any workaround for the 2 issues exposed above?Thanks in advance