This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes hibernate composite key problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate composite key problem" Watch "hibernate composite key problem" New topic
Author

hibernate composite key problem

vibhuti shrotria
Greenhorn

Joined: Mar 18, 2009
Posts: 2
hi..
I am new to hibernate and using it to connect to database.i have a composite key(firstname and lastname).
I am getting error as:
Remote Exception: java.rmi.RemoteException: EJB Exception: ; nested exception is
:
java.lang.ExceptionInInitializerError

My bean class and composite id classes are as:

package com.iwms.hibernate.JavaBeans.TEST;

public class Try {
/**
*
*/

private TryCK tryCK;
private int age;

public Try() {
tryCK = new TryCK();
}

public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getFirstname() {
return this.tryCK.getFirstname();
}

public void setFirstname(String firstname) {
this.tryCK.setFirstname(firstname);
}

public String getLastname() {
return this.tryCK.getLastname();
}

public void setLastname(String lastname) {
this.tryCK.setLastname(lastname);
}
}

package com.iwms.hibernate.JavaBeans.TEST;

import java.io.Serializable;





public class TryCK implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String firstname;
private String lastname;

public TryCK()
{

}

public TryCK(TryCK tryCK)
{
this.firstname=tryCK.firstname;
this.lastname=tryCK.lastname;

}

public boolean equals(Object obj) {
if(this == obj)
return true;
if((obj == null) || (obj.getClass() != this.getClass()))
return false;
TryCK tryCK = (TryCK)obj;
return (this.firstname.equals(tryCK.firstname) &&
this.lastname.equals(tryCK.lastname));
}

public int hashCode () {

return 0;
}

public String getFirstname() {
return firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}



}

Mapping file is as:
<hibernate-mapping>

<class name="com.iwms.hibernate.JavaBeans.TEST.Try" table="TRY">
<composite-id name="id"
class="com.iwms.hibernate.JavaBeans.TEST.TryCK">

<key-property name="firstname" column="first_name"
type="java.lang.String" length="30" />
<key-property name="lastname" column="last_name"
type="java.lang.String" length="30" />


</composite-id>

<!-- Normal properties of a java class -->


<property name="age" type="java.lang.Integer" column="AGE" />


</class>
</hibernate-mapping>

query that i hav written is:
Transaction tx=session.beginTransaction();
try{
session.save(rpd);
tx.commit();
log.info("Record successfully inserted");
flag=true;
}

please could anyone sort it out..Its urgent..
Thanks in advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What is the exception? Can you post the stacktrace?

(NB: we have an ORM forum which is a better place to post these sorts of questions - someone will move this shortly).


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
vibhuti shrotria
Greenhorn

Joined: Mar 18, 2009
Posts: 2
Remote Exception: java.rmi.RemoteException: EJB Exception: ; nested exception is
:
java.lang.ExceptionInInitializerError
java.rmi.RemoteException: EJB Exception: ; nested exception is:
java.lang.ExceptionInInitializerError
at weblogic.ejb.container.internal.EJBRuntimeUtils.throwRemoteException(
EJBRuntimeUtils.java:95)
at weblogic.ejb.container.internal.BaseEJBObject.handleSystemException(B
aseEJBObject.java:713)
at weblogic.ejb.container.internal.BaseEJBObject.handleSystemException(B
aseEJBObject.java:681)
at weblogic.ejb.container.internal.BaseEJBObject.preInvoke(BaseEJBObject
.java:229)
at weblogic.ejb.container.internal.StatelessEJBObject.preInvoke(Stateles
sEJBObject.java:64)
at com.iwms.sessionbeans.TEST.TryBean_mbea8w_EOImpl.doInsert(TryBean_mbe
a8w_EOImpl.java:42)
at com.iwms.sessionbeans.TEST.TryBean_mbea8w_EOImpl_CBV.doInsert(Lcom.iw
ms.hibernate.JavaBeans.TEST.Try;)Z(Unknown Source)
at com.iwms.framework.BusinessDelegator.doInsert(BusinessDelegator.java:
1834)
at com.iwms.web.TEST.TryAction.doPost(TryAction.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run
(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecuri
tyHelper.java:127)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:283)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:3211)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppS
ervletContext.java:1983)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletC
ontext.java:1890)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.j
ava:1344)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
Caused by: java.lang.ExceptionInInitializerError
at com.iwms.hibernate.client.HibernateSessionFactory.<clinit>(HibernateS
essionFactory.java:16)
at com.iwms.sessionbeans.TEST.TryBean.<init>(TryBean.java:33)
at com.iwms.sessionbeans.TEST.TryBean_mbea8w_Impl.<init>(TryBean_mbea8w_
Impl.java:35)
at java.lang.Class.newInstance(I)Ljava.lang.Object;(Unknown Source)
at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBMan
ager.java:197)
at weblogic.ejb.container.manager.StatelessManager.createBean(StatelessM
anager.java:292)
at weblogic.ejb.container.pool.StatelessSessionPool.createBean(Stateless
SessionPool.java:174)
at weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSes
sionPool.java:105)
at weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessMa
nager.java:143)
at weblogic.ejb.container.internal.BaseEJBObject.preInvoke(BaseEJBObject
.java:213)
... 19 more
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for
id in class com.iwms.hibernate.JavaBeans.TEST.Try
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicProper
tyAccessor.java:282)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyA
ccessor.java:275)
at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:16
8)
at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyF
actory.java:44)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.jav
a:123)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(Abstrac
tEntityPersister.java:434)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(Sing
leTableEntityPersister.java:109)
at org.hibernate.persister.PersisterFactory.createClassPersister(Persist
erFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:
226)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav
a:1294)
at com.iwms.hibernate.client.HibernateSessionFactory.<clinit>(HibernateS
essionFactory.java:13)
at com.iwms.sessionbeans.TEST.TryBean.<init>(TryBean.java:33)
at com.iwms.sessionbeans.TEST.TryBean_mbea8w_Impl.<init>(TryBean_mbea8w_
Impl.java:35)
at java.lang.Class.newInstance(I)Ljava.lang.Object;(Unknown Source)
at weblogic.ejb.container.manager.BaseEJBManager.allocateBean(BaseEJBMan
ager.java:197)
at weblogic.ejb.container.manager.StatelessManager.createBean(StatelessM
anager.java:292)
at weblogic.ejb.container.pool.StatelessSessionPool.createBean(Stateless
SessionPool.java:174)
at weblogic.ejb.container.pool.StatelessSessionPool.getBean(StatelessSes
sionPool.java:105)
at weblogic.ejb.container.manager.StatelessManager.preInvoke(StatelessMa
nager.java:143)
at weblogic.ejb.container.internal.BaseEJBObject.preInvoke(BaseEJBObject
.java:213)
at weblogic.ejb.container.internal.StatelessEJBObject.preInvoke(Stateles
sEJBObject.java:64)
at com.iwms.sessionbeans.TEST.TryBean_mbea8w_EOImpl.doInsert(TryBean_mbe
a8w_EOImpl.java:42)
at com.iwms.sessionbeans.TEST.TryBean_mbea8w_EOImpl_CBV.doInsert(Lcom.iw
ms.hibernate.JavaBeans.TEST.Try;)Z(Unknown Source)
at com.iwms.framework.BusinessDelegator.doInsert(BusinessDelegator.java:
1834)
at com.iwms.web.TEST.TryAction.doPost(TryAction.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run
(StubSecurityHelper.java:225)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecuri
tyHelper.java:127)
false
<Mar 18, 2009 4:14:21 PM GMT+05:30> <Warning> <org.hibernate.connection.DriverMa
nagerConnectionProvider> <000000> <problem closing pooled connection
java.sql.SQLException: Io exception: Socket closed
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:255)
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:480)
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:1
184)
 
wood burning stoves
 
subject: hibernate composite key problem
 
Similar Threads
jspSetProperty Doubt??
Error setting the expression with value [Ljava.lang.String;@1d05b0a
doubt in ActionForms
Hibernate mapping
Mapping in Hibernate for nested Bean Structure