|
From: <leg...@at...> - 2003-07-30 06:57:14
|
The following comment has been added to this issue:
Author: Max Rydahl Andersen
Created: Wed, 30 Jul 2003 1:56 AM
Body:
idea: could we explicitly check reflectively for if equals and hashcode is implemented for the required classes ? (just to help the users)
---------------------------------------------------------------------
View the issue:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-214
Here is an overview of the issue:
---------------------------------------------------------------------
Key: HB-214
Summary: Deadlock in processing "composite-id -> key-many-to-one"
Type: Bug
Status: Closed
Priority: Major
Resolution: REJECTED
Project: Hibernate2
Assignee:
Reporter: Shining
Created: Mon, 28 Jul 2003 5:28 AM
Updated: Tue, 29 Jul 2003 8:36 PM
Environment: Windows2000 Professional with SP3, SQL Server 2000, Microsoft SQLServer 2000 JDBC Driver, SUN JDK 1.4.1_02, Elcipse 2.1
Description:
I want use multi-primary-key and foriegn-key as primary-key in my project. The insert and update operator can work correctly, but the load operator can not work correctly. After tracing the source code of hibernate, I think problem is the process of the <composition-id> with <key-many-to-one> element.
I can not sure it is a bug or hibernate can not support my database schema. What can I do?
My Sample is:
-----------------------DataBase Schema---------------------------------
/*==============================================================*/
/* Table: TBL_DWZT_NCS */
/*==============================================================*/
create table TBL_DWZT_NCS (
ZT_BM char(10) not null,
DW_BZDM char(40) not null,
NCS_FLYS_BM FLYS_BM not null,
NCS_YEFX JDBZ not null,
NCS_YE JE not null,
constraint PK_TBL_DWZT_NCS primary key (ZT_BM, DW_BZDM, NCS_FLYS_BM)
)
go
/*==============================================================*/
/* Table: TBL_DWZT_NCSHB */
/*==============================================================*/
create table TBL_DWZT_NCSHB (
ZT_BM char(10) not null,
DW_BZDM char(40) not null,
NCS_FLYS_BM FLYS_BM not null,
NCSHB_DM HB_DM not null,
NCSHB_YE JE not null,
constraint PK_TBL_DWZT_NCSHB primary key (ZT_BM, DW_BZDM, NCS_FLYS_BM, NCSHB_DM)
)
go
alter table TBL_DWZT_NCSHB
add constraint FK_DWZT_NCS_HB foreign key (ZT_BM, DW_BZDM, NCS_FLYS_BM)
references TBL_DWZT_NCS (ZT_BM, DW_BZDM, NCS_FLYS_BM)
on update cascade on delete cascade
go
-----------------------NCS.hbm.xml-------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="jdo.NCS" table="TBL_DWZT_NCS">
<!--<jcs-cache usage="read-write"/>-->
<composite-id>
<key-property name="dw_bzdm" column="DW_BZDM"/>
<key-property name="zt_bm" column="ZT_BM"/>
<key-property name="flys_bm" column="NCS_FLYS_BM"/>
</composite-id>
<property name="yefx" column="NCS_YEFX" type="int"/>
<property name="YE" column="NCS_YE" type="double"/>
<set name="hbs" cascade="save-update">
<key>
<column name="DW_BZDM"/>
<column name="ZT_BM"/>
<column name="NCS_FLYS_BM" />
</key>
<one-to-many class="jdo.NCSHB"/>
</set>
</class>
</hibernate-mapping>
-----------------------NCSHB.hbm.xml-------------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="jdo.NCSHB" table="TBL_DWZT_NCSHB">
<!--<jcs-cache usage="read-write"/>-->
<composite-id>
<key-many-to-one name="ncs" class="jdo.NCS">
<column name="DW_BZDM"/>
<column name="ZT_BM"/>
<column name="NCS_FLYS_BM" />
</key-many-to-one>
<key-property name="hb_dm" column="NCSHB_DM"/>
</composite-id>
<property name="ye" column="NCSHB_YE" type="double"/>
</class>
</hibernate-mapping>
----------------------------NCS.java----------------------------------
/*
* Created on 2003-7-10
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package jdo;
import java.io.Serializable;
import java.util.Set;
import java.util.HashSet;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class NCS implements Serializable {
private String dw_bzdm;
private String zt_bm;
private String flys_bm;
private FLYS flys;
private int yefx;
private double ye;
private Set hbs;
/**
* @return
*/
public String getDw_bzdm() {
return dw_bzdm;
}
/**
* @return
*/
public String getFlys_bm() {
return flys_bm;
}
/**
* @return
*/
public double getYE() {
return ye;
}
/**
* @return
*/
public int getYefx() {
return yefx;
}
/**
* @return
*/
public String getZt_bm() {
return zt_bm;
}
/**
* @param string
*/
public void setDw_bzdm(String string) {
dw_bzdm = string;
}
/**
* @param string
*/
public void setFlys_bm(String string) {
flys_bm = string;
}
/**
* @param d
*/
public void setYE(double d) {
ye = d;
}
/**
* @param string
*/
public void setYefx(int i) {
yefx = i;
}
/**
* @param string
*/
public void setZt_bm(String string) {
zt_bm = string;
}
public Set getHbs() {
return hbs;
}
void setHbs(Set hbs) {
this.hbs = hbs;
}
void addHb(NCSHB ncshb)
{
if (hbs == null)
hbs = new HashSet();
hbs.add(ncshb);
}
/**
* @return
*/
public FLYS getFlys() {
return flys;
}
/**
* @param flys
*/
public void setFlys(FLYS flys) {
this.flys = flys;
}
}
----------------------------NCSHB.java----------------------------------
/*
* Created on 2003-7-10
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package jdo;
import java.io.Serializable;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class NCSHB implements Serializable {
private NCS ncs;
private String hb_dm;
private double ye;
/**
* @return
*/
public String getHb_dm() {
return hb_dm;
}
/**
* @return
*/
public double getYe() {
return ye;
}
/**
* @return
*/
public NCS getNcs() {
return ncs;
}
/**
* @param string
*/
public void setHb_dm(String string) {
hb_dm = string;
}
/**
* @param d
*/
public void setYe(double d) {
ye = d;
}
/**
* @param ncs
*/
public void setNcs(NCS ncs) {
this.ncs = ncs;
}
}
----------------------------hibernate.properties-----------------------
######################
### Query Language ###
######################
## define query language constants / function names
hibernate.query.substitutions true 1, false 0, yes 'Y', no 'N'
## package imports
#hibernate.query.imports net.sf.hibernate.test, net.sf.hibernate.eg
#################
### Platforms ###
#################
## MS SQL Server
hibernate.dialect net.sf.hibernate.dialect.SybaseDialect
hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
#hibernate.connection.url jdbc:microsoft:sqlserver://192.168.0.3:1433;DatabaseName=FIMS_XTGL;SelectMethod=cursor
hibernate.connection.url jdbc:microsoft:sqlserver://192.168.0.3:1433;DatabaseName=FIMS_ZWGL;SelectMethod=cursor
hibernate.connection.username sa
hibernate.connection.password
#################################
### Hibernate Connection Pool ###
#################################
#hibernate.connection.pool_size 1
#hibernate.statement_cache.size 25
###################################
### Apache DBCP Connection Pool ###
###################################
## connection pool
hibernate.dbcp.maxActive 100
hibernate.dbcp.whenExhaustedAction 1
hibernate.dbcp.maxWait 120000
hibernate.dbcp.maxIdle 10
## prepared statement cache
hibernate.dbcp.ps.maxActive 100
hibernate.dbcp.ps.whenExhaustedAction 1
hibernate.dbcp.ps.maxWait 120000
hibernate.dbcp.ps.maxIdle 100
## optional query to validate pooled connections:
#hibernate.dbcp.validationQuery select 1 from dual
#hibernate.dbcp.testOnBorrow true
#hibernate.dbcp.testOnReturn false
#################################
### Plugin ConnectionProvider ###
#################################
## use a custom ConnectionProvider (if not set, Hibernate will choose a built-in ConnectionProvider using hueristics)
#hibernate.connection.provider_class net.sf.hibernate.connection.DriverManagerConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.DatasourceConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.C3P0ConnectionProvider
hibernate.connection.provider_class net.sf.hibernate.connection.DBCPConnectionProvider
#hibernate.connection.provider_class net.sf.hibernate.connection.ProxoolConnectionProvider
#######################
### Transaction API ###
#######################
## the Transaction API abstracts application code from the underlying JTA or JDBC transactions
#hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
#hibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactory
## to use JTATransactionFactory, Hibernate must be able to locate the UserTransaction in JNDI
## default is java:comp/UserTransaction
#jta.UserTransaction jta/usertransaction
#jta.UserTransaction javax.transaction.UserTransaction
#jta.UserTransaction UserTransaction
## to use JTATransactionFactory with JCS caching, Hibernate must be able to obtain the JTA TransactionManager
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.JBossTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.OrionTransactionManagerLookup
#hibernate.transaction.manager_lookup_class net.sf.hibernate.transaction.ResinTransactionManagerLookup
##############################
### Miscellaneous Settings ###
##############################
## print all generated SQL to the console
hibernate.show_sql true
## specify a JDBC isolation level
#hibernate.connection.isolation 4
## set the JDBC fetch size
#hibernate.jdbc.fetch_size 25
## set the maximum JDBC 2 batch size (a nonzero value enables batching)
hibernate.jdbc.batch_size 0
## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)
#hibernate.jdbc.use_scrollable_resultset true
## use streams when writing binary types to / from JDBC
hibernate.jdbc.use_streams_for_binary true
## specify a default schema for unqualified tablenames
#hibernate.default_schema test
## use a custom stylesheet for XML generation (if not specified, hibernate-default.xslt will be used)
#hibernate.xml.output_stylesheet C:/Hibernate/net/sf/hibernate/hibernate-default.xslt
## enable outerjoin fetching (specifying a Dialect will cause Hibernate to use sensible default)
#hibernate.use_outer_join false
## enable CGLIB reflection optimizer (enabled by default)
#hibernate.cglib.use_reflection_optimizer false
############
### JNDI ###
############
## specify a JNDI name for the SessionFactory
#hibernate.session_factory_name hibernate/session_factory
## Hibernate uses JNDI to bind a name to a SessionFactory and to look up the JTA UserTransaction;
## if hibernate.jndi.* are not specified, Hibernate will use the default InitialContext() which
## is the best approach in an application server
#file system
#hibernate.jndi.class com.sun.jndi.fscontext.RefFSContextFactory
#hibernate.jndi.url file:/
#WebSphere
#hibernate.jndi.class com.ibm.websphere.naming.WsnInitialContextFactory
#hibernate.jndi.url iiop://localhost:900/
----------------------------Test.java----------------------------------
1 try {
2 // configure the Configuration
3 ds = new Configuration()
4 .addClass(jdo.NCS.class)
5 .addClass(jdo.NCSHB.class);
6
7 // build a SessionFactory
8 sessions = ds.buildSessionFactory();
9
10 Session sess = sessions.openSession();
11
12 NCS ncs = null;
13
14 Iterator iter = sess.iterate("FROM NCS ncs");
15 while (iter.hasNext()) {
16 ncs = (NCS) iter.next();
17 sess.delete(ncs);
18 }
19
20 ncs = new NCS();
21 ncs.setDw_bzdm("0001");
22 ncs.setZt_bm("01");
23 ncs.setFlys_bm("[][][][][][][][]");
24 ncs.setYefx(1);
25 ncs.setYE(1000.00);
26
NCSHB ncshb = null;
ncshb = new NCSHB();
ncshb.setNcs(ncs);
ncshb.setHb_dm("RMB");
ncshb.setYe(1000.00);
ncs.addHb(ncshb);
sess.save(ncs);
ncs = new NCS();
ncs.setDw_bzdm("0002");
ncs.setZt_bm("01");
ncs.setFlys_bm("[01][][][][][][][]");
ncs.setYefx(1);
ncs.setYE(900.00);
ncshb = new NCSHB();
ncshb.setNcs(ncs);
ncshb.setHb_dm("RMB");
ncshb.setYe(900.00);
ncs.addHb(ncshb);
ncshb = new NCSHB();
ncshb.setNcs(ncs);
ncshb.setHb_dm("USD");
ncshb.setYe(100.00);
ncs.addHb(ncshb);
sess.save(ncs);
sess.delete(ncs);
sess.flush();
sess.connection().commit();
sess.close();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Deadlock occured in line 14, the session.iterator()
------------------------------Erro Message----------------------------
Hibernate: select ncs0_.DW_BZDM as x0_0_, ncs0_.ZT_BM as x0_1_, ncs0_.NCS_FLYS_BM as x0_2_ from TBL_DWZT_NCS ncs0_
Hibernate: select ncs0_.DW_BZDM as DW_BZDM, ncs0_.ZT_BM as ZT_BM, ncs0_.NCS_FLYS_BM as NCS_FLYS_BM, ncs0_.NCS_YEFX as NCS_YEFX, ncs0_.NCS_YE as NCS_YE from TBL_DWZT_NCS ncs0_ where ncs0_.DW_BZDM=? and ncs0_.ZT_BM=? and ncs0_.NCS_FLYS_BM=?
Hibernate: select tbl_dwzt0_.DW_BZDM as DW_BZDM__, tbl_dwzt0_.ZT_BM as ZT_BM__, tbl_dwzt0_.NCS_FLYS_BM as NCS_FLYS3___, tbl_dwzt0_.NCSHB_DM as NCSHB_DM__, tbl_dwzt0_.DW_BZDM as DW_BZDM, tbl_dwzt0_.ZT_BM as ZT_BM, tbl_dwzt0_.NCS_FLYS_BM as NCS_FLYS_BM, tbl_dwzt0_.NCSHB_DM as NCSHB_DM, tbl_dwzt0_.NCSHB_YE as NCSHB_YE from TBL_DWZT_NCSHB tbl_dwzt0_ where tbl_dwzt0_.DW_BZDM=? and tbl_dwzt0_.ZT_BM=? and tbl_dwzt0_.NCS_FLYS_BM=?
Hibernate: select ncs0_.DW_BZDM as DW_BZDM, ncs0_.ZT_BM as ZT_BM, ncs0_.NCS_FLYS_BM as NCS_FLYS_BM, ncs0_.NCS_YEFX as NCS_YEFX, ncs0_.NCS_YE as NCS_YE from TBL_DWZT_NCS ncs0_ where ncs0_.DW_BZDM=? and ncs0_.ZT_BM=? and ncs0_.NCS_FLYS_BM=?
Hibernate: select tbl_dwzt0_.DW_BZDM as DW_BZDM__, tbl_dwzt0_.ZT_BM as ZT_BM__, tbl_dwzt0_.NCS_FLYS_BM as NCS_FLYS3___, tbl_dwzt0_.NCSHB_DM as NCSHB_DM__, tbl_dwzt0_.DW_BZDM as DW_BZDM, tbl_dwzt0_.ZT_BM as ZT_BM, tbl_dwzt0_.NCS_FLYS_BM as NCS_FLYS_BM, tbl_dwzt0_.NCSHB_DM as NCSHB_DM, tbl_dwzt0_.NCSHB_YE as NCSHB_YE from TBL_DWZT_NCSHB tbl_dwzt0_ where tbl_dwzt0_.DW_BZDM=? and tbl_dwzt0_.ZT_BM=? and tbl_dwzt0_.NCS_FLYS_BM=?
..............
---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
If you want more information on JIRA, or have a bug to report see:
http://www.atlassian.com/software/jira
|