I'm having some problems when inserting records under certain circumstances.
I'm in the process of trying to do a fairly simple prototype using a few different solutions - Hibernate being one of them. I am extremely impressed with the level of documentation and the breadth of the functionality. It appears to be just what i need. Now, i need to see if it can do what i need it to do.
I've just started working with it yesterday, and it seems to be working great. However, i've taken most of the "defaults" so far, since i haven't had the time to analyze each and every attribute. I actually rean into this problem with a class hierarchy persistance model that i got working. I dropped back to this simple scenario to isolate what i'm seeing.
Anyhow, below is the mapping file, then a snippet of code, and an explanation of what i'm seeing. Thanks for the help.
Address Table with an identity field in Microsoft SQL.
<hibernate-mapping>
<class name="trivin.test.persist.Address" table="ADDRESS">
<id name="addressID" column="addressID" type="long">
<generator class="identity"/>
</id>
<property name="street1" />
<property name="street2" />
<property name="street3" />
<property name="city" />
<property name="state" />
<property name="zipCode" column="zip" />
<property name="county" />
<property name="country" />
</class>
</hibernate-mapping>
The code below is simple. newAddress(String) simply populates it with data.
...
Code:
try {
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
Address anAddress = newAddress("1");
session.save(anAddress);
// Address anAddress2 = newAddress("2");
// session.save(anAddress2); //!!! get cloned error on this line.
tx.commit();
session.close();
}
catch (HibernateException ex) {
}
...
When i run it as is, i have no problems using Microsoft SQL JDBC Driver. If I use jTDS Driver (since the forum suggested using it) I can't even add the single record. I get.
ERROR - could not insert: [trivin.test.persist.Address]
java.sql.SQLException: Was expecting a result set
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeQuery(PreparedStatement_base.java:214)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:508)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:432)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:906)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:839)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:757)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:720)
at trivin.test.persist.Persist.addressTest(Persist.java:50)
at trivin.test.persist.Persist.main(Persist.java:20)
So, jTDS cannot even insert a single record, it appear to be having problem with entity? don't see it with the other driver.
Back using Microsoft JDBC Driver, it works fine, until i uncomment the 2 lines, creating 2 separate objects, doing 2 saves, and a commit. On the second save i get the following error. See below code for full dump.
WARN - SQL Error: 0, SQLState: 08007
ERROR - [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
WARN - SQL Error: 0, SQLState: 08007
ERROR - [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
ERROR - could not insert: [trivin.test.persist.Address]
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
WARN - SQL Error: 0, SQLState: 08007
ERROR - [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
WARN - SQL Error: 0, SQLState: 08007
ERROR - [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.
ERROR - could not insert: [trivin.test.persist.Address]
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 Source)
at com.microsoft.jdbc.base.BaseStatement.setupImplConnection(Unknown Source)
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 Source)
at com.microsoft.jdbc.base.BaseConnection.prepareStatement(Unknown Source)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:249)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:61)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:505)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:432)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:906)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:839)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:757)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:720)
at trivin.test.persist.Persist.addressTest(Persist.java:50)
at trivin.test.persist.Persist.main(Persist.java:20)
Note that i'm testing using Microsoft SQL Server, production will probably take place in a few months on Oracle, when i decide what mapping solution i want to use. I've noticed a few places where answers to questions were "use another driver". I've seen "driver not recommended". I don't mind doing that, if there is a known problem or reason for it. I'm hoping that it's not a rock fetch. When and if i commit to using this, i want to feel "somewhat" comfortable that i won't have to keep searching for "compatible" technologies.
Any input or help would be much appreciated.
ps. i love thedocumentation, samples, etc. I was up and working in an hour. I'm looking forward to using this product. Hope i can.