-->
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.  [ 8 posts ] 
Author Message
 Post subject: applicationContext-hibernate.xml,sentinelle.hbm.xml & OR
PostPosted: Tue Jan 11, 2005 1:05 pm 
Newbie

Joined: Mon Dec 27, 2004 11:16 am
Posts: 4
Location: Singapore
Dear Friends,

I am new to hibernate, a DBA assigned the task of migrating MYSQL database to Oracle. I have already migrated the data. To perform a basic test, I have been told to make necessary changes in applicationContext-hibernate.xml and sentinelle.hbm.xml.

I have tried to read everywhere in this site but not able to find a sample which helps in making changes necessary for oracle.

Kindly help to either provide a sample or point me in the right direction.

TIA.

Grover

PS:
My applicationContext-hibernate.xml and portion of sentinelle.hbm.xml are as follows :

sentinelle.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping auto-import="true">
<class name="com.myapp.sentinelle.entity.User" table="tb_user">
<cache usage="read-write" />
<id name="userId" column="userId" type="long" unsaved-value="-1">
<generator class="identity"/>
</id>
<property name="userName" column="userName" />
<property name="password" column="password" />
<property name="role" column="role" />
<one-to-one name="buyer" class="com.myapp.sentinelle.entity.Buyer" cascade="all" />
<one-to-one name="seller" class="com.myapp.sentinelle.entity.Seller" cascade="all" />
<many-to-one name="company" class="com.myapp.sentinelle.entity.Company" column="companyId" cascade="none" />
</class>
<class name="com.myapp.sentinelle.entity.Buyer" table="tb_buyer">
<cache usage="read-write" />
<id name="userId" column="userId" type="long">
<generator class="assigned"/>
</id>
<property name="firstName" column="firstName" />
<property name="midName" column="midName" />
<property name="lastName" column="lastName" />
<property name="email" column="email" />
<one-to-one name="user" class="com.myapp.sentinelle.entity.User" cascade="none" />
<bag name="details" lazy="false" inverse="false" cascade="all">
<cache usage="read-write" />
<key column="userId" />
<one-to-many class="com.myapp.sentinelle.entity.PaymentAdvice" />
</bag>
</class>
........
........


applicationContext-hibernate.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@localhost:1521:ora10gdb</value></property>
<property name="username"><value>LFUSER</value></property>
<property name="password"><value>LFUSER</value></property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">

<property name="dataSource"><ref local="dataSource"/></property>

<property name="mappingResources">
<value>com/myapp/sentinelle/persistence/hibernate/sentinelle.hbm.xml</value>

</property>

<property name="hibernateProperties">

<props>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>

<prop key="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</prop>

<prop key="hibernate.show_sql">true</prop>

<prop key="hibernate.connection.provider_class">net.sf.hibernate.connection.DBCPConnectionProvider</prop>

<prop key="hibernate.cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</prop>

<prop key="hibernate.dbcp.whenExhaustedAction">1</prop>

<prop key="hibernate.dbcp.maxActive">100</prop>

<prop key="hibernate.dbcp.maxWait">120000</prop>

<prop key="hibernate.dbcp.maxIdle">10</prop>

</props>

</property>

</bean>

<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->

<bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>

</bean>
<bean id="userDAO" class="com.myapp.sentinelle.persistence.hibernate.dao.UserDAOHibe">

<property name="sessionFactory"><ref local="sessionFactory"/></property>

</bean>
<bean id="lineDAO" class="com.myapp.sentinelle.persistence.hibernate.dao.LineDAOHibe" >

<property name="sessionFactory"><ref local="sessionFactory" /> </property>

</bean>


<bean id="purchDAO" class="com.myapp.sentinelle.persistence.hibernate.dao.PurchDAOHibe" >

<property name="sessionFactory"><ref local="sessionFactory" /> </property>

</bean>

<bean id="planDAO" class="com.myapp.sentinelle.persistence.hibernate.dao.PlanDAOHibe" >

<property name="sessionFactory"><ref local="sessionFactory" /> </property>

</bean>

<bean id="messageDAO" class="com.myapp.sentinelle.persistence.hibernate.dao.MessageDAOHibe">

<property name="sessionFactory"><ref local="sessionFactory"/></property>

</bean>

</beans>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 1:08 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
What is your actual problem? I doubt someone will port the application for you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 11, 2005 9:56 pm 
Newbie

Joined: Mon Dec 27, 2004 11:16 am
Posts: 4
Location: Singapore
Thanks for looking into this.

If possible, I have to test the application with oracle database. The applicationContext-hibernate.xml and sentinelle.hbm.xml files have been configured w.r.t. mysql database. I would like to know what changes should be made in these files for oracle. (oracle schema has been created same as mysql).

eg in hibernate-mapping,

1. "generator class= ??" (this is either identity or assigned for mysql)
2. any changes needed in following :
<property name="userName" column="userName" />

Is the column name case sensitive ?

The application team would involve from next week and they would prefer that I at least setup these two files by then.

Thanks & regards,
Grover


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 6:28 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Just a suggestion, but you might want to read the Hibernate reference material and possibly go buy the "Hibernate In Action." After that you'll have an understanding of the files you're editing. Someone could post an answer, but without a basic understanding of Hibernate you'll just run into another problem.

BTW, the application-context-spring.xml file is a Spring Framework file. While the Spring Framework does have hibernate suport, you won't get much help on it from this forum. Add the Spring Framework reference to your list of homework reading assignments.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 9:43 pm 
Newbie

Joined: Mon Dec 27, 2004 11:16 am
Posts: 4
Location: Singapore
I just needed basic info with regards to oracle and got a kick-start at
http://technology.amis.nl/blog/index.php?p=137

Thank you Jasper.

I have tried to read though reference material but it is either too complex for me or kind of very simple info I need is not readily available.

can a guru please help me with the following specifically:

1. In hibernate mapping, for oracle is it always
generator class="native"

2. Should we specifiy both of following or only Oracle9Dialect will be enough ?
key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect
key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:02 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
The answer to 1) is: It depends. Are you using Oracle's sequences to generate your ID's? If you are then you need to set your generator property to either "native" or "sequence" If' you aren't using sequences, then you need to pick a generator that will work for your application. See:

http://www.hibernate.org/hib_docs/refer ... aration-id

The answer to 2) is: You only specify one dialect for Hibernate. If you need Oracle9 features, use that one. If your queries won't work with that, use the other one.

Other than that, what exactly are the errors you're seeing during startup?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 3:42 am 
Newbie

Joined: Mon Dec 27, 2004 11:16 am
Posts: 4
Location: Singapore
Thanks a lot for providing help and a pointer to relevant info.

I have another question related to this.

Is it possible to not generate or assign primary key values before it attempts to save record ?
I wish to use Oracle's database triggers to generate primary key values as it invloves some complex logic which I would like to code within database.

I tried removing generator tag but it complains as it seems to be mandatory to specify this.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 3:26 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
It is true that the Generator mapping attribute is required. You have to have one, even if you're doing the generation yourself. Since you have your own complex case you may have to create your own generator. It's easy to do, all you have to do is implement net.sf.hibernate.id.IdentifierGenerator, which is a very simple interface. You then use the class name for your new generator in the mapping:

Code:
<id name="id" type="long" column="uid" unsaved-value="0">
        <generator class="your.class.here.CustomGenerator">
                <param name="someProperty">someValue</param>
        </generator>
</id>

Remember to replace the your.class.here.CustomGenerator and the property value with your custom class.

For more information check the reference manual at:
http://www.hibernate.org/hib_docs/refer ... -generator

and the JavaDoc:
http://www.hibernate.org/hib_docs/api/n ... rator.html

You should find it very easy to use your own identifier generation scheme.


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