Migrating from Hibernate to EclipseLink [message #1228503] |
Tue, 07 January 2014 06:20  |
Eclipse User |
|
|
|
Hi All,
I am new to Eclipse Link...
I have to migrate my application from hibernate to eclipselink.
Before the actual issue, can you suggest which version of EclipseLink I could go, which is stable and widely used?
And here is my issue,
Following query am trying to execute,
SELECT x FROM UserVo x (which has 4 rows in db)
Here, the UserVo object creation is happening only when I do the following,
EntityManager entityManager = entityManagerFactory.createEntityManager();
but on actualy query execution below, no initilization of the class occurs,
Query q = entityManager.createQuery("SELECT x FROM UserVo x");
In case of hibernate , it will do initlization for indivdual entries in the table. So, if its similar, it should invoke the default constructor 4 times, but this is not happeng with case of eclipse link.
Actually I would like to inilizatize an additional attribute which is not actually in db, within this constructor, so could not able to achieve it.
Can you pls help me on this.
Let me know if you need more details.
|
|
|
Re: Migrating from Hibernate to EclipseLink [message #1229041 is a reply to message #1228503] |
Wed, 08 January 2014 10:38   |
Eclipse User |
|
|
|
I assume you mean that the default constructor is not being called when you actually execute the query, and are not expecting the constructor to be called on the createQuery call.
If so, EclipseLink uses bytecode enhancement to implement optimizations. One of which is probably causing your default constructor to be bypassed, allowing EclipseLink to more efficiently create instances without initializing attributes that it will then have to replace anyway when it loads the data from the database. You can verify this by having EclipseLink write out the end result of its weaving process by running the static weaver on your classes and inspecting them with a decompiler to see how they have changed. Running static weaving is described here:
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving
If this is related to the problem, you might try disabling internal weaving optimizations by setting the eclipselink.weaving.internal persistence property to false, as described here:
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Disabling_Weaving_with_Persistence_Unit_Properties
If you want to rely on non-persistence properties being set in entities though, you might be better to use a postLoad event to ensure they are they are set.
As for versions, I'd recommend always starting with the latest released to get all the latest bug fixes. No point re-diagnosing issues that have already been fix in my mind, and you get all the latest features you may not need yet, but might in the future.
|
|
|
|
|
|
Re: Migrating from Hibernate to EclipseLink [message #1229494 is a reply to message #1229487] |
Thu, 09 January 2014 10:03  |
Eclipse User |
|
|
|
Here is my mapping file,
Can u suggest if anything wrong,
<entity-mappings>
<description>Users</description>
<entity name="JurisdictionVoLink" class="com.csfb.csar.exman.shared.work.JurisdictionVoLink" >
<table name="VEM_JURISDICTION"></table>
<attributes>
<id name="dbId" type="java.lang.Long" >
<column name = "JURISDICTION_ID"/>
</id>
<basic name="description" type="java.lang.String" >
<column name="DESCRIPTION"/>
</basic>
</attributes>
</entity>
</entity-mappings>
And my entity class,
public class JurisdictionVoLink implements java.io.Serializable, Cloneable {
private Long dbId;
private String description;
/** default constructor */
public JurisdictionVoLink() {
System.out.println("default constructor JurisdictionVoLink invoked");
}
public JurisdictionVoLink(Long dbId, String description) {
super();
System.out.println("All argument constructor JurisdictionVoLink invoked");
this.dbId = dbId;
this.description = description;
}
public Long getDbId() {
return dbId;
}
public void setDbId(Long dbId) {
this.dbId = dbId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public JurisdictionVoLink clone(){
System.out.println("Clone JurisdictionVoLink invoked");
JurisdictionVoLink obj = null;
try{
obj = (JurisdictionVoLink) super.clone();
}catch(CloneNotSupportedException e){
e.printStackTrace();
}
return obj;
}
public boolean equals(Object obj){
System.out.println("equals JurisdictionVoLink invoked");
JurisdictionVoLink workItem = null;
workItem = (JurisdictionVoLink) obj;
if(workItem.dbId.equals(dbId))return true;
return false;
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.06594 seconds