-->
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.  [ 2 posts ] 
Author Message
 Post subject: Wired behavior of composite-element
PostPosted: Thu Sep 16, 2004 10:08 am 
Newbie

Joined: Thu Sep 16, 2004 5:28 am
Posts: 1
Hibernate version: 2.1.6

Mapping documents:
<class name="ecomm.tool.model.db.Products" table="products">

<id name="id" type="long" column="products_id" unsaved-value="0">
<generator class="identity"/>
</id>

<property name="quantity" type="int">
<column name="products_quantity" sql-type="int" not-null="true"/>
</property>
<property name="model" type="java.lang.String">
<column name="products_model" sql-type="varchar" not-null="false"/>
</property>
<property name="price" type="float">
<column name="products_price" sql-type="decimal" not-null="true"/>
</property>
<property name="dateAdded" type="java.util.Date">
<column name="products_date_added" sql-type="datetime" not-null="true"/>
</property>
<property name="lastModified" type="java.util.Date">
<column name="products_last_modified" sql-type="datetime" not-null="false"/>
</property>
<property name="dateAvailable" type="java.util.Date">
<column name="products_date_available" sql-type="datetime" not-null="false"/>
</property>
<property name="weight" type="float">
<column name="products_weight" sql-type="decimal" not-null="true"/>
</property>
<property name="image" type="java.lang.String">
<column name="products_image" sql-type="varchar" not-null="false"/>
</property>
<property name="status" type="int">
<column name="products_status" sql-type="tinyint" not-null="true"/>
</property>
<property name="supplier" type="java.lang.String">
<column name="supplier" sql-type="varchar" not-null="false"/>
</property>


<set name="descr" lazy="true" cascade="save-update" table="products_description">
<key column="products_id"/>
<composite-element class="ecomm.tool.model.db.ProductsDescription">
<property name="language" type="int">
<column name="language_id" sql-type="int" not-null="true"/>
</property>
<property name="descr" type="java.lang.String">
<column name="products_description" sql-type="text"/>
</property>
<property name="name" type="java.lang.String">
<column name="products_name" sql-type="varchar" not-null="true"/>
</property>
<property name="url" type="java.lang.String">
<column name="products_url" sql-type="varchar"/>
</property>
</composite-element>
</set>
</class>

Code between sessionFactory.openSession() and session.close():
Session session = getMainImporter().getHibernate().openSession();
Transaction tx = session.beginTransaction();

Products dbProd = (Products) session.get(Products.class, new Long(id));

dbProd.setPrice(parsePrice(price, model, cat));
dbProd.setLastModified(new java.util.Date());
dbProd.setQuantity(parseQuantity(row));

String image = dbProd.getImage();
String url = null;

Set set = dbProd.getDescr();

Iterator it = set.iterator();

if (it.hasNext()) {
ProductsDescription dbProdDescr = (ProductsDescription) it.next();
//url = dbProdDescr.getUrl();
}

session.update(dbProd);

removeFromProductsMap(dbProd.getModel());

tx.commit();

session.close();



Full stack trace of any exception that occurs:

2004-09-16 15:59:36,684: WARN: SQL Error: 1062, SQLState: 23000
2004-09-16 15:59:36,699: ERROR: Duplicate key or integrity constraint violation, message from server: "Duplicate entry '1-4' for key 1"
2004-09-16 15:59:36,703: ERROR: could not insert collection rows: [ecomm.tool.model.db.Products.descr#1]
java.sql.SQLException: Duplicate key or integrity constraint violation, message from server: "Duplicate entry '1-4' for key 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1741)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1588)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:608)
at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:49)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2374)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at ecomm.tool.importer.supplier.Common.updateProductToDb(Common.java:368)
at ecomm.tool.importer.supplier.Common.processIt(Common.java:579)
at ecomm.tool.importer.MainImporter.dbImport(MainImporter.java:117)
at ecomm.tool.importer.MainImporter.main(MainImporter.java:162)
2004-09-16 15:59:36,710: ERROR: Could not synchronize database state with session
net.sf.hibernate.JDBCException: could not insert collection rows: [ecomm.tool.model.db.Products.descr#1]
at net.sf.hibernate.collection.AbstractCollectionPersister.insertRows(AbstractCollectionPersister.java:622)
at net.sf.hibernate.impl.ScheduledCollectionUpdate.execute(ScheduledCollectionUpdate.java:49)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2374)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at ecomm.tool.importer.supplier.Common.updateProductToDb(Common.java:368)
at ecomm.tool.importer.supplier.Common.processIt(Common.java:579)
at ecomm.tool.importer.MainImporter.dbImport(MainImporter.java:117)
at ecomm.tool.importer.MainImporter.main(MainImporter.java:162)


Name and version of the database you are using: MySQL 3.23


Does anyone here have a clue why it's trying to insert a duplicate key entry ? That's and update, i get the Products from DB corectly with the get then update something and commit the transaction ... so why is should cause a duplicate key ?? Everything is already in the DB.

Thanks for any hint

_________________
That's me


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 12:34 pm 
Newbie

Joined: Tue Nov 22, 2005 11:57 am
Posts: 5
Did you remember to override hashCode() and equals() of class ProductsDescription?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.