-->
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: Problem persisting List and Array of persistable objects..
PostPosted: Mon Oct 18, 2004 5:09 pm 
Newbie

Joined: Thu Sep 23, 2004 2:35 pm
Posts: 5
Hello,
Please help.. It's kinda urgent.. Can't figure out what is wrong...

I have an object "HbmTradeHistory" . It is mapped and it's working just fine.. I can perform query agaist the database and retrive objects from it..

Now I'm getting to the point where I need to populate the database..
My program is creating a Vector of these HbmTradeHistory objects and I want to store them in DB.. (There are NEW objects... ) So I need to attach them to a session... the Id field in them is NULL and it's configured to be auto generated by DB.. And it works for single objects..

I can succesfully store each of them separately, but I'd like to be able to take a whole bunch of them and do it in one shot...
According to "Hibernate in Action" I should be able to do it on List or Set or Array object.. I'm trying to attach NEW objects to the session and persist it.. But Hibernate tells me that it DOES not have a persister for these types.. I tried List, I tried Array.. The attached below code shows what i'm doing..

Please help.. This must be so trivial!!! And Im missing some simple point..

Also, I've read the whole book.. They do not have a SINGLE example of how to store a bunch of objects in one shot.. They have an example of an object that has an attribute which is a collection.. But my case is simpler..
I don't have an attribute that maps to another table, I have a list of objects that just have to go into a single table... They all objects with simple attributes from the same table...



Hibernate version: 2.1

Mapping documents:

<?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="com.b.db.persistent.HbmTradeHistory" table="trade_history">
<id name="id" column="Id" type="long">
<generator class="native"/>
</id>
<property name="userId" column="userId" type="string" length="15" not-null="true"/>
<property name="tradeReference" column="tradeRef" type="string" length="30" not-null="true"/>
<property name="instrumentId" column="instrumentId" type="string" length="15" not-null="true"/>
<property name="instrumentName" column="instrumentName" type="string" length="30" not-null="true"/>
<property name="tradePrice" column="tradePrice" type="big_decimal" not-null="true"/>
<property name="transactionType" column="indicatorBuySell" type="string" not-null="true"/>
<property name="activeP" column="ActiveP" type="string" not-null="true"/>
<property name="tradeSettlementPrice" column="settlementPrice" type="big_decimal" not-null="true"/>
<property name="tradeSize" column="tradeSize" type="big_decimal" not-null="true"/>
<property name="tradeTime" column="tradeDate" type="date" not-null="true"/>
<property name="tradeSettlementTime" column="settleDate" type="date" not-null="true"/>
<property name="priceI" column="priceI" type="int" not-null="true"/>
<property name="tradingSystemId" column="tsSystemId" type="string" length="15" not-null="true"/>
<property name="orderId" column="orderId" type="string" not-null="true"/>
</class>
</hibernate-mapping>


---------------------





Code between sessionFactory.openSession() and session.close():


public void persist (HbmTradeHistory[] tradeHistory) throws HibernateException {

Transaction trans = hbmSession.beginTransaction();
hbmSession.lock(tradeHistory,LockMode.NONE);
hbmSession.saveOrUpdate(tradeHistory);
trans.commit();

}



Full stack trace of any exception that occurs:

16:35:29,190 INFO Environment:469 - Hibernate 2.1.6
16:35:29,190 INFO Environment:503 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=net.sf.hibernate.cache.EhCacheProvider, hibernate.cache.use_query_cache=true, hibernate.max_fetch_depth=1, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.connection.username=root, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:mysql://localhost/beacon-billing, hibernate.show_sql=true, hibernate.connection.password=mysql, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
16:35:29,190 INFO Environment:528 - using java.io streams to persist binary types
16:35:29,190 INFO Environment:529 - using CGLIB reflection optimizer
16:35:29,206 INFO Configuration:350 - Mapping resource: com/beacon/db/persistent/HbmTradeHistory.hbm.xml
16:35:29,456 INFO Binder:229 - Mapping class: com.beacon.db.persistent.HbmTradeHistory -> trade_history
16:35:29,550 INFO Configuration:350 - Mapping resource: com/beacon/db/persistent/HbmTransRevenueReport.hbm.xml
16:35:29,581 INFO Binder:229 - Mapping class: com.beacon.db.persistent.HbmTransRevenueReport -> trans_revenue_report
16:35:29,581 INFO Configuration:350 - Mapping resource: com/beacon/db/persistent/HbmInstrumentAssetClass.hbm.xml
16:35:29,597 INFO Binder:229 - Mapping class: com.beacon.db.persistent.HbmInstrumentAssetClass -> instrument_asset_class
16:35:29,612 INFO Configuration:350 - Mapping resource: com/beacon/db/persistent/HbmUser.hbm.xml
16:35:29,628 INFO Binder:229 - Mapping class: com.beacon.db.persistent.HbmUser -> customer_users
16:35:29,643 INFO Configuration:350 - Mapping resource: com/beacon/db/persistent/HbmCustomer.hbm.xml
16:35:29,643 INFO Binder:229 - Mapping class: com.beacon.db.persistent.HbmCustomer -> Customer
16:35:29,659 INFO Configuration:627 - processing one-to-many association mappings
16:35:29,659 INFO Configuration:636 - processing one-to-one association property references
16:35:29,659 INFO Configuration:661 - processing foreign key constraints
16:35:29,675 INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
16:35:29,675 INFO SettingsFactory:59 - Maximim outer join fetch depth: 1
16:35:29,675 INFO SettingsFactory:63 - Use outer join fetching: true
16:35:29,690 INFO DriverManagerConnectionProvider:42 - Using Hibernate built-in connection pool (not for production use!)
16:35:29,690 INFO DriverManagerConnectionProvider:43 - Hibernate connection pool size: 1
16:35:29,690 INFO DriverManagerConnectionProvider:77 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/beacon-billing
16:35:29,690 INFO DriverManagerConnectionProvider:78 - connection properties: {user=root, password=mysql}
16:35:29,706 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
16:35:29,909 INFO SettingsFactory:103 - Use scrollable result sets: true
16:35:29,909 INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): true
16:35:29,909 INFO SettingsFactory:109 - Optimize cache for minimal puts: false
16:35:29,909 INFO SettingsFactory:115 - echoing all SQL to stdout
16:35:29,909 INFO SettingsFactory:118 - Query language substitutions: {no='N', true=1, yes='Y', false=0}
16:35:29,909 INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.EhCacheProvider
16:35:29,925 INFO SettingsFactory:141 - query cache factory: net.sf.hibernate.cache.StandardQueryCacheFactory
16:35:29,925 INFO Configuration:1116 - instantiating and configuring caches
Session Terminated:
16:35:30,065 INFO SessionFactoryImpl:118 - building session factory
16:35:30,284 INFO ReflectHelper:186 - reflection optimizer disabled for: com.beacon.db.persistent.HbmUser, BulkBeanException: Property is private (property setUserIdType)
16:35:30,456 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
16:35:30,456 INFO UpdateTimestampsCache:35 - starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
16:35:30,487 WARN EhCache:94 - Could not find configuration for net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the defaultCache settings.
16:35:30,503 INFO StandardQueryCache:41 - starting query cache at region: net.sf.hibernate.cache.StandardQueryCache
16:35:30,503 WARN EhCache:94 - Could not find configuration for net.sf.hibernate.cache.StandardQueryCache. Configuring using the defaultCache settings.
net.sf.hibernate.MappingException: No persister for array result, likely a broken query
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2690)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2697)
at net.sf.hibernate.impl.SessionImpl.lock(SessionImpl.java:1705)
at com.beacon.db.persistent.TradeHistoryPersistor.persist(TradeHistoryPersistor.java:50)
at com.beacon.boffice.billing.GeneveTest.run(GeneveTest.java:116)




Name and version of the database you are using:
MySQL mysql-4.0.21-win


The generated SQL (show_sql=true):

Did not get to that point
Debug level Hibernate log excerpt:




Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 27, 2004 1:27 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
I had faced the same situation once and the javadoc clearly says that the save and similar methods look at the objects identifier. What I did to save all these was similar to the following:

Code:
Transaction trans = hbmSession.beginTransaction();
//hbmSession.lock(tradeHistory,LockMode.NONE);
for(int i = 0; i< tradeHistory.length; i++) {
    hbmSession.saveOrUpdate(tradeHistory[i]);
}
trans.commit();


This way the transaction commit occurs only once. I do not know of any other way.

_________________
Thanks
Sameet


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.