Help! ! ! Hibernate composite primary keys and foreign keys for many relationship problems!

Category: Java EE
 
mature_1983
2013-08-20 02:24:16

Sponsored Links
Table xhmission which has two fields Missionid, MissionSeq (all int) they are as a composite primary key, of course, there are other words

segments.
table taskData1, the primary key is workID, xhmission foreign key is the primary key of the table.

table xhmission corresponding primary key class XhMissionPK as:
public class XhMissionPK implements Serializable {
/ / fieds
private int missionid;
private int missionSeq;
..
}
table xhmission corresponding class is:
public class XhMission implements Serializable {
private ; static final long serialVersionUID = 1L;
/ / Fields
private XhMissionPK xhMissionPK;
private String contNo;
....
private int priority;
private Set <TaskData1> taskData1s;
/ / setter - getter
...
}

table taskData1 corresponding class is:
public class TaskData1 implements Serializable {
/ / fields
private int workID;
private int missionID;
private int missionSeq;
. . . .
private XhMission xhMission;
/ / setter - getter
....
}
xhmission.hbm.xml as:

<hibernate-mapping package="com.itthinker.payroll.pojo">
<class name="XhMission" table="XhMission" schema="dbo">
< composite-id name = "xhMissionPK">
<key-property name="missionid">
</ key-property>
<key-property name = "missionSeq"> </ key-property>
</ composite-id>
; <property name="contNo" column="contNo"> </property>
...
<property name="priority" column="priority"> </property>

<set name = "taskData1s" cascade = "all" inverse = " true "fetch =" join ">
<key column="xhMissionPK"> </key>
<one-to-many class="com.itthinker.payroll.pojo.TaskData1"/>
</set>
</class>
</ hibernate-mapping> ;

taskData1.hbm.xml as:

<hibernate-mapping package="com.itthinker.payroll.pojo">
<class name="TaskData1" table="TaskData1">
<id name = "taskID" column = "taskID">
<generator class="identity">
</generator> ;
</id>
<property name="missionID" column="missionID"> </property>
...
<property name="missionSeq" column="missionSeq"> </property>

<property name = " ; taskID "column =" taskID "> </property>
<many-to-one name="xhMission">
<column name = "xhMissionPK"> </column>
</ many-to-one>
</class>
</ hibernate-mapping>

applicationContext-core.xml as:
<beans default-autowire="byName">
<! - DataSource definition ->
<bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource" destroy-

method = "close">
<property name = "driverClassName"

value = "com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<property name = "url"

value = "jdbc: microsoft: sqlserver :/ / 127.0.0.1:1433; databaseName = sunyard" />
<property name="username" value="sa" />
<property name = "password" value = "sa" ;/>
</bean>

<! - Hibernate SessionFactory ->
<bean id = "sessionFactory"

class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name = "dataSource" ref = "dataSource" />
<property name="mappingLocations">
<list>
<value> classpath :/ com / itthinker / payroll / hbm / XhMission.hbm. xml </value>
<value> classpath :/ com/itthinker/payroll/hbm/TaskData1.hbm.xml </value>
</list>
</property> ;
<property name="hibernateProperties">
<props>
<prop

key = "hibernate.dialect"> ; org.hibernate.dialect.DB2Dialect </prop>
<prop key="hibernate.show_sql"> true </prop>
</props>
</property>
</bean>

<! - Transaction manager for a single Hibernate SessionFactory ->
< ; bean id = "transactionManager"
class = "org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name = "sessionFactory" ref = " ; sessionFactory "/>
</bean>

<! - Auto proxy driven by JDK 5 + Annotation - >
<bean class = "org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"

/>

<bean

class = "org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor" ref="transactionInterceptor" />
</bean> ;

<bean id = "transactionInterceptor"
class = "org.springframework.transaction.interceptor . TransactionInterceptor ">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributeSource">
<bean

class = "org.springframework.transaction.annotation. AnnotationTransactionAttributeSource "/>
</property>
</bean>
; <bean id="xhMissionDao" class="com.itthinker.payroll.dao.impl.XhMissionDaoImp" />
<bean id = "taskData1Dao" class = "com.itthinker.payroll.dao.impl.TaskData1DaoImp" />
</beans>

TaskData1DaoImp.java as:
public class ; TaskData1DaoImp ​​extends HibernateDaoSupport implements TaskData1Dao {
public void save (TaskData1 taskData1) {
/ / TODO Auto-generated method stub
getHibernateTemplate (). saveOrUpdate (taskData1);
}
}

unit test classes TaskData1DaoTest.java as: public class TaskData1DaoTest extends

TestCase {
ApplicationContext cxt;
String path = "com / itthinker / payroll / dao / applicationContext-core.xml";
TaskData1Dao taskData1Dao;
public TaskData1DaoTest (String name) {
super (name);
}
public void setUp () {
cxt = new ClassPathXmlApplicationContext (path);
taskData1Dao = (TaskData1DaoImp) cxt.getBean ("taskData1Dao");
}
public void tearDown () {
cxt ; = null;
taskData1Dao = null;
}

public static Test suite () {
TestSuite suite = ; new TestSuite ();
suite.addTest (new TaskData1DaoTest ("testAdd"));
return suite;
}
public void testAdd () {
TaskData1 taskData1 = new TaskData1 ();
taskData1.setFlag (1);
taskData1.setMissionID (123);
taskData1.setMissionSeq (123) ;
System.out.println ("0");
taskData1Dao.save (taskData1);
System.out.println ("1");
}
}
nothing when tested output, abnormal as follows:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor' defined in

class path resource [com / itthinker / payroll / dao / applicationContext-core.xml ]: Cannot resolve

reference to bean 'transactionInterceptor' while setting bean property

'transactionInterceptor'; nested ; exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'transactionInterceptor' defined in class path resource

[com / itthinker / payroll / dao / applicationContext-core.xml]: Cannot resolve reference to bean

'transactionManager' while setting bean property 'transactionManager'; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating ; bean with name

'transactionManager' defined in class path resource

[com / itthinker / payroll / dao / applicationContext-core . xml]: Cannot resolve reference to bean

'sessionFactory' while setting bean property 'sessionFactory'; nested exception is

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

'sessionFactory' defined in class path resource '

engage in a long time did not solve this problem, the younger beginner, an expert please enlighten me! ! Another: the younger brother of all in this,! !


Sponsored Links

pcrazy1991
2013-08-20 02:39:27
try

<bean id="taskData1Dao" class="com.itthinker.payroll.dao.impl.TaskData1DaoImp" /> 
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
jf99401316
2013-08-20 02:43:15
ah,, the sound is still scouring ah. . .
Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.