Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Migrating from Hibernate to EclipseLink(Migrating from Hibernate to EclipseLink)
Migrating from Hibernate to EclipseLink [message #1228503] Tue, 07 January 2014 06:20 Go to next message
Sendhil Kumar is currently offline Sendhil Kumar
Messages: 7
Registered: January 2014
Junior Member
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 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
Registered: July 2009
Senior Member
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 #1229381 is a reply to message #1229041] Thu, 09 January 2014 05:28 Go to previous messageGo to next message
Sendhil Kumar is currently offline Sendhil Kumar
Messages: 7
Registered: January 2014
Junior Member
Hi Chris, thanks for your suggestions,

but its not only the contructor not getting invoked, even my attribute setter methods also not getting invoked. Do you knwo how JPA actually constructs entity objects and populate the values into it? Or is there any reference link that you can share me on this?

Also, am getting following warning when am doing Persistence.createEntityManagerFactory(), I doubt eclipse link is not being used, instead OpenJPA being used (we are using JAP 6.0 framework) ,

WARNING: Found unrecognized persistence provider "org.eclipse.persistence.jpa.PersistenceProvider" in place of OpenJPA provider. This provider's properties will not be used.

Re: Migrating from Hibernate to EclipseLink [message #1229484 is a reply to message #1229041] Thu, 09 January 2014 09:41 Go to previous messageGo to next message
Sendhil Kumar is currently offline Sendhil Kumar
Messages: 7
Registered: January 2014
Junior Member
Hi Chris, after adding,

<property name="eclipselink.weaving" value="false"/>

its invoking the default constructor now !!!!

But still the attribute setters are not being invoked. Any idea why this is happening? But column values are getting loaded properly anyhow.

Actually I have to do some additional operation on the setter as shown below, as its not invoking my setter, could not able to do this,

public void setDbId(Long dbId) {
this.dbId = dbId;
identity.setKey(dbId);
}

Re: Migrating from Hibernate to EclipseLink [message #1229487 is a reply to message #1229484] Thu, 09 January 2014 09:50 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
Registered: July 2009
Senior Member
Check your entity and how it is defined, as setters will only be used if property access is used. It is a common mistake to mix annotations on both fields and properties which is unspecified in JPA. Providers should only use one or the other, and so ignore the rest, and will then use property or field access for the entity. I believe in JPA 2.0 came the ability to specify the access type for the entity and override it for specific fields/properties so that field or property access be used in special cases.
Re: Migrating from Hibernate to EclipseLink [message #1229494 is a reply to message #1229487] Thu, 09 January 2014 10:03 Go to previous message
Sendhil Kumar is currently offline Sendhil Kumar
Messages: 7
Registered: January 2014
Junior Member
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;
}

}


Previous Topic:[SOLVED] Single-Table Multitenancy and Cross-Tenant Access
Next Topic:How to configure Inner Class as an Entity in Mapping File
Goto Forum:
  


Current Time: Sun Apr 20 17:59:54 EDT 2014

Powered by FUDForum. Page generated in 0.01712 seconds