-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Mapping Problems
PostPosted: Fri Oct 03, 2008 4:00 am 
Newbie

Joined: Fri Oct 03, 2008 3:08 am
Posts: 2
Hello,

I am testing Hibernate for an application that is already built. I wanted to implement one business service with Hibernate and then compare that implementation with the old one that is using JDBC (through Spring). I have problems mapping the classes below, though, and I would really appreciate if someone could help me or give me some tips on how to proceed. This is my object structure (which I cannot change since the code is generated):

VoGenericProduct
private List voGenericProductParentList;
public VoGenericProductParentList getVoGenericProductParentList();
public void setVoGenericProductParentList(VoGenericProductList list);
+ fields...

VoGenericProductParentList (this class is not an derived from Collection)
private Vector collection; // <-- contains VoGenericProductParents
public List getCollection();
public void setCollection();
+ fields...

VoGenericProductParent
A lot of fields and properties (see Hibernate mapping files below).

Note that it works when I remove the relation between the classes and query only one table at a time...

I also have another question: How do I configure Hibernate for read-only usage? Is it even possible? (The application is a read-only server-side application..)

Hibernate version: 3.3.1 (on jdk 1.4.2).

Mapping documents:

VoGenericProduct.hbm.xml
<hibernate-mapping>
<class name="vo.VoGenericProduct" table="GEN_PRODUCT_V">
<id name="genericProductNo" column="GENPRD_NO" type="java.lang.String"></id>
<property name="genericProductName" column="GENPRD_NAME" type="java.lang.String"></property>
<property name="language" column="LANG_CODE_ISO" type="java.lang.String"></property>
<property name="country" column="CTY_CODE_ISO" type="java.lang.String"></property>
<property name="validFrom" column="VALID_FROM" type="java.util.Date"></property>
<property name="validTo" column="VALID_TO" type="java.util.Date"></property>
<property name="haveItems" column="HAVE_ITEMS_YN" type="true_false"></property>
<property name="updateDate" column="UPD_DATE" type="java.util.Date"></property>
<property name="deleteDate" column="DELETE_DATE" type="java.util.Date"></property>
<component name="voGenericProductParentList" insert="false" update="false">
<list name="collection" access="property">
<key column="GENPRD_NO"/>
<index column="PARENT_TYPE"></index>
<one-to-many class="vo.VoGenericProductParent"/>
</list>
</component>
</hibernate-mapping>

VoGenericProductParent.hbm.xml
<hibernate-mapping>
<class name="vo.VoGenericProductParent" table="GENPRD_PARENT_V">
<id name="parentNo" column="PARENT_NO" type="java.lang.String">
<generator class="assigned"></generator>
</id>
<property name="parentType" column="PARENT_TYPE" type="java.lang.String" not-null="false"></property>
<property name="validFrom" column="VALID_FROM" type="java.util.Date" not-null="false"></property>
<property name="validTo" column="VALID_TO" type="java.util.Date" not-null="false"></property>
<property name="updateDate" column="UPD_DATE" type="java.util.Date" not-null="false"></property>
<property name="deleteDate" column="DELETE_DATE" type="java.util.Date" not-null="false"></property>
</class>


Code between sessionFactory.openSession() and session.close():
Using Spring:
ApplicationContext context = new ClassPathXmlApplicationContext("ds-context.xml");
SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");
HibernateTemplate template = new HibernateTemplate(sessionFactory);
List list = template.find("from VoGenericProduct v where v.genericProductNo = 00636 " +
"and v.country = 'GB'");
System.out.println(list.size());

Full stack trace of any exception that occurs:
INFO: Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 10.2.0.1.0
Oct 3, 2008 9:29:03 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle8iDialect
Oct 3, 2008 9:29:03 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Oct 3, 2008 9:29:03 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: on_close
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Oct 3, 2008 9:29:03 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory createRegionFactory
INFO: Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Oct 3, 2008 9:29:03 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Oct 3, 2008 9:29:04 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Oct 3, 2008 9:29:04 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
org.springframework.orm.hibernate3.HibernateSystemException: Exception occurred inside setter of vo.VoGenericProductParentList.collection; nested exception is org.hibernate.PropertyAccessException: Exception occurred inside setter of vo.VoGenericProductParentList.collection
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:659)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:847)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:839)
at aaaa.hibernate.test.Test.<init>(Test.java:22)
at aaaa.hibernate.test.Test.main(Test.java:28)
Caused by: org.hibernate.PropertyAccessException: Exception occurred inside setter of vo.VoGenericProductParentList.collection
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:89)
at org.hibernate.tuple.component.AbstractComponentTuplizer.setPropertyValues(AbstractComponentTuplizer.java:104)
at org.hibernate.tuple.component.PojoComponentTuplizer.setPropertyValues(PojoComponentTuplizer.java:118)
at org.hibernate.type.ComponentType.setPropertyValues(ComponentType.java:381)

Name and version of the database you are using:
Oracle 8.1.4

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Best regards,

Simon


Last edited by pawn81 on Fri Oct 03, 2008 5:41 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Recommendation
PostPosted: Fri Oct 03, 2008 4:49 am 
Newbie

Joined: Fri Sep 26, 2008 4:01 am
Posts: 10
I have a few questiond and some suggestions

1. Why do use vectors
Quote:
private Vector collection; // <-- contains VoGenericProductParents


I would suggest to use Set

I will just give an EG

Code:
public class Order  implements java.io.Serializable {


     private long id;
     private Account account;
     private Set resources = new HashSet(0);
..................
}



and the associated hbm file has
Code:
<hibernate-mapping>
    <class name="Order" table="ORDER" schema="SRINARA">
        <id name="id" type="long">
            <column name="ID" scale="0" />

            <generator class="assigned" />
        </id>

        <many-to-one name="account" class="Account" fetch="select">
            <column name="ACCOUNT_ID" scale="0" not-null="true" />
        </many-to-one>

         <set name="resources" inverse="false" table="ORDER_ASSOCIATION" cascade="save-update">
            <key>
                <column name="ORDER_ID" scale="0" not-null="true" />
            </key>

            <many-to-many entity-name="Resource">
                <column name="RESOURCE_ID" scale="0" not-null="true" />
            </many-to-many>
        </set>   </class>
</hibernate-mapping>



2. And as U said the app is already there, I hope the DB schema is also already there I would recommend to reverse engineer all the entity POJOS and the DAO as well as the DAOimpl from the schema itself.

chec out hibernate tools - reverse engineering .. have to tune template ..

3. If Ur using Spring Framework I would suggest U to extend HbernateDaoSupport which allow U to getHibernateTemplate() which will do away with SessionFactory


Top
 Profile  
 
 Post subject: Rate It Buddy
PostPosted: Fri Oct 03, 2008 4:51 am 
Newbie

Joined: Fri Sep 26, 2008 4:01 am
Posts: 10
Love to get some credits ...
rate em buddy


Top
 Profile  
 
 Post subject: Re: Recommendation
PostPosted: Fri Oct 03, 2008 5:16 am 
Newbie

Joined: Fri Oct 03, 2008 3:08 am
Posts: 2
SriSasken wrote:
I have a few questiond and some suggestions

1. Why do use vectors
Quote:
private Vector collection; // <-- contains VoGenericProductParents


I would suggest to use Set

I will just give an EG

Code:
public class Order  implements java.io.Serializable {


     private long id;
     private Account account;
     private Set resources = new HashSet(0);
..................
}



-----

2. And as U said the app is already there, I hope the DB schema is also already there I would recommend to reverse engineer all the entity POJOS and the DAO as well as the DAOimpl from the schema itself.

chec out hibernate tools - reverse engineering .. have to tune template ..

3. If Ur using Spring Framework I would suggest U to extend HbernateDaoSupport which allow U to getHibernateTemplate() which will do away with SessionFactory


Hello and thanks for your reply. I see that I did not write the object structure correctly, it should be:

============================
VoGenericProduct
private VoGenericProductParentList voGenericProductParentList;
public List getVoGenericProductParentList();
public void setVoGenericProductParentList(VoGenericProductList list);
+ fields...

VoGenericProductParentList (this class is not an derived from Collection)
private Vector collection; // <-- contains VoGenericProductParents
public List getCollection();
public void setCollection();
+ fields...

VoGenericProductParent
A lot of fields and properties (see Hibernate mapping files below).
============================

The problem is that VoGenericProductParentList is not a subclass of Collection - but it has a property called collection that is a Vector. Unfortunately I have to live with this setup since the code is generated.

The problem is that I don't really know how to map the relationship. The basic structure is that each VoGenericProduct has many VoGenericProductParents. The relation in the code, though, is that each VoGenericProduct has a VoGenericProductList which has a collection (Vector) containing VoGenericProductParents. The VoGenericProductList may seem like a stupid implementation but as said before, I cannot do anything about it...

Yes, the tables do exist in the database.

Best regards,

Simon


Top
 Profile  
 
 Post subject: implement the org.hibernate.usertype.UserCollection
PostPosted: Mon Oct 06, 2008 5:11 am 
Newbie

Joined: Fri Sep 26, 2008 4:01 am
Posts: 10
http://www.hibernate.org/hib_docs/reference/en-US/html/collections.html



Rate this buddy !


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