-->
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.  [ 4 posts ] 
Author Message
 Post subject: Question about saving objects
PostPosted: Fri Dec 24, 2004 11:44 am 
Newbie

Joined: Fri Dec 24, 2004 11:24 am
Posts: 5
Hibernate version:2.1.2

Mapping documents:
Person.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="eg.Person" table="person" >
<id name="id" column="id">

<generator class="foreign">
<param name="property">cat</param>
</generator>
</id>
<property name="alias" column="alias" />
<one-to-one name="cat" class="eg.Cat1" cascade="all" constrained="true" />
</class>
</hibernate-mapping>
Cat1.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="eg">
<class name="Cat1" table="CATS" discriminator-value="C">
<id name="id" column="uid" type="long">
<generator class="identity"/>
</id>
<discriminator column="subclass" type="character"/>
<property name="birthdate" type="date"/>
<!--<property name="color" not-null="true"/>-->
<property name="sex" not-null="true" update="false"/>
<property name="weight"/>
<many-to-one name="mate" column="mate_id"/>
<!--<set name="kittens">
<key column="mother_id"/>
<one-to-many class="Cat1"/>
</set>-->
<subclass name="DomesticCat" discriminator-value="D">
<property name="name" type="string"/>
</subclass>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Cat1 cat1 = new Cat1();
cat1.setSex('2');
cat1.setWeight(90);
cat1.setBirthdate(new java.util.Date());

Person person = new Person();
person.setAlias("fuckperson");
person.setCat(cat1);

Transaction tx = session.beginTransaction();
session.save(person);
session.flush();
tx.commit();


Full stack trace of any exception that occurs:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a
cloned connection while in manual transaction mode.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Sour
ce)
at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Sou
rce)
at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Sourc
e)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Sourc
e)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.ja
va:249)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:6
1)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:5
6)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.j
ava:109)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav
a:460)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav
a:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.j
ava:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at eg.AppTest.main(AppTest.java:48)
23:35:46,901 ERROR SessionImpl:2343 - Could not synchronize database state with
session
net.sf.hibernate.JDBCException: could not insert: [eg.Person#39]
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav
a:478)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav
a:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.j
ava:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2335)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
at eg.AppTest.main(AppTest.java:48)
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can
't start a cloned connection while in manual transaction mode.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source
)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getImplConnection(Unknown Sour
ce)
at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Sou
rce)
at com.microsoft.jdbc.base.BaseStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.<init>(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Sourc
e)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Sourc
e)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.ja
va:249)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:6
1)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:5
6)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.j
ava:109)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.jav
a:460)
... 6 more


Name and version of the database you are using:
Microsoft SQL Server2000


The generated SQL (show_sql=true):
insert into CATS (birthdate, sex, weight, mate_id, subclass) values (
?, ?, ?, ?, 'C') select SCOPE_IDENTITY()
insert into person (alias, id) values (?, ?)


Debug level Hibernate log excerpt:
What does this mean?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 12:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Use a third party JDBC driver, Microsoft one is *really* broken and we do not support it. JTDS is free and great.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: o
PostPosted: Fri Dec 24, 2004 12:37 pm 
Newbie

Joined: Fri Dec 24, 2004 11:24 am
Posts: 5
thank you,i will try it,but where i can get it?
emmanuel wrote:
Use a third party JDBC driver, Microsoft one is *really* broken and we do not support it. JTDS is free and great.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 24, 2004 12:45 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use Google!


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

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.