-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: how to set composite key in jpa+hybernate
PostPosted: Tue Nov 02, 2010 11:06 am 
Newbie

Joined: Tue Nov 02, 2010 10:55 am
Posts: 17
Hi
I am using jpa+ hybernate orm mapping.Here i am not using annotations.I am using ORM.xml,persistence.xml and application config files.

example
my ORM.xml file is

<entity class="com.evolvus.common.model.TaSystemConfiguration"
name="TaUser">
<table name="ta_User" />
<attributes>
<id name="networkListenerMapId">
<column name="user_ID"/>
<generated-value strategy="TABLE" />
</id>
<basic name="name">
<column name="user_name" />
</basic>
<basic name="PassWord">
<column name="pass_word" />
</basic>
</attributes>
</entity>

my persistence.xml file is

<persistence-unit name="userProject" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/orm.xml</mapping-file>
<class>com.evolvus.common.model.TaSystemConfiguration</class></persistence-unit>

my implementation its working fine.I am new for this jpa implementation.But here i have one problem for my requirements i have to use composite key,that i know how to use in hybernate,i could not use composite key in jpa.Is there is anyway to acheive this plz give me any solution
My hibernate mapping files are given below. I need to convert this into jpa + hibernate implementation s
taSystemConfiguration.java
public class TaSystemConfiguration implements java.io.Serializable {

private String attributeCode;

private String attributeValue;

private TaEntity taEntity;

public int getAttributeCode() {
return attributeCode;
}

public void setAttributeCode(int attributeCode) {
this.attributeCode = attributeCode;
}

public TaSystemConfiguration() {

}

/*public String getAttributeCode() {
return this.attributeCode;
}

public void setAttributeCode(String attributeCode) {
this.attributeCode = attributeCode;
}*/

public String getAttributeValue() {
return this.attributeValue;
}

public void setAttributeValue(String attributeValue) {
this.attributeValue = attributeValue;
}

public TaEntity getTaEntity() {
return this.taEntity;
}

public void setTaEntity(TaEntity taEntity) {
this.taEntity = taEntity;
}

public TaSystemConfiguration(int attributeCode, String attributValue,
TaEntity taEntity) {
this.attributeCode = attributeCode;
this.attributeValue = attributValue;
this.taEntity = taEntity;
}

public TaSystemConfiguration(int attributeCode, TaEntity taEntity) {
this.attributeCode = attributeCode;
this.taEntity = taEntity;
}
}
and my hbm file is
<hibernate-mapping>
<class name="com.evolvus.common.model.TaSystemConfiguration" table="ta_system_configuration">
<comment></comment>
<composite-id>
<key-property name="attributeCode" type="string">
<column name="ATTRIBUTE_CODE" />
</key-property>
<key-many-to-one name="taEntity" class="com.evolvus.common.model.TaEntity" >
<column name="ENTITY_ID" not-null="true" unique="true">
<comment></comment>
</column>
</key-many-to-one>
</composite-id>
<property name="attributeValue" type="string">
<column name="ATTRIBUTE_VALUE" length="100">
<comment></comment>
</column>
</property>
</class>
</hibernate-mapping>
i converted this into jpa+ hybernate, i have done the coding like this
TaSystemConfiguration.java
public class TaSystemConfiguration implements java.io.Serializable {


private String attributeValue;

private TaEntity taEntity;

private int attributeCode;
public int getAttributeCode() {
return attributeCode;
}

public void setAttributeCode(int attributeCode) {
this.attributeCode = attributeCode;
}

public TaSystemConfiguration() {

}

/*public String getAttributeCode() {
return this.attributeCode;
}

public void setAttributeCode(String attributeCode) {
this.attributeCode = attributeCode;
}*/

public String getAttributeValue() {
return this.attributeValue;
}

public void setAttributeValue(String attributeValue) {
this.attributeValue = attributeValue;
}

public TaEntity getTaEntity() {
return this.taEntity;
}

public void setTaEntity(TaEntity taEntity) {
this.taEntity = taEntity;
}

public TaSystemConfiguration(int attributeCode, String attributValue,
TaEntity taEntity) {
this.attributeCode = attributeCode;
this.attributeValue = attributValue;
this.taEntity = taEntity;
}

public TaSystemConfiguration(int attributeCode, TaEntity taEntity) {
this.attributeCode = attributeCode;
this.taEntity = taEntity;
}
}
and this is my composite key pojo class

public class TaSystemConfigurationPK implements java.io.Serializable
{
private TaEntity taEntity;

private int attributeCode;


public TaSystemConfigurationPK()
{
}
/**
* @return the taEntity
*/
public TaEntity getTaEntity() {
return taEntity;
}

/**
* @param taEntity the taEntity to set
*/
public void setTaEntity(TaEntity taEntity) {
this.taEntity = taEntity;
}

/**
* @return the attributeCode
*/
public int getAttributeCode() {
return attributeCode;
}

/**
* @param attributeCode the attributeCode to set
*/
public void setAttributeCode(int attributeCode) {
this.attributeCode = attributeCode;
}


and my orm.xml is like

<entity class="com.evolvus.common.model.TaSystemConfiguration"
name="TaSystemConfiguration">
<table name="ta_system_configuration"/>
<id-class class="com.evolvus.common.model.TaSystemConfigurationPK"/>
<attributes>
<id name="attributeCode">
<column name="ATTRIBUTE_CODE"/>
</id>
<basic name="attributeValue">
<column name="ATTRIBUTE_VALUE" length="100" />
</basic>
<many-to-one name="taEntity" target-entity="TaEntity"
optional="false">
<join-column name="ENTITY_ID" insertable="false"
nullable="false" />
</many-to-one>
</attributes>
</entity>


any one,could you tel me where i did wrong..
my advance thanks to all


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.