-->
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.  [ 3 posts ] 
Author Message
 Post subject: Question regarding mapping for legacy database
PostPosted: Tue Apr 04, 2006 12:57 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1
Mapping documents:
The account mapping file
<class
name="com.maintenance.Account"
table="account"
>

<id
name="account"
type="java.lang.String"
column="account"
>
<meta attribute="use-in-equals">true</meta>
<generator class="assigned" />
</id>

<property
name="status"
type="java.lang.String"
column="status_"
not-null="true"
length="1"

<property
name="accountType"
type="java.lang.String"
column="account_type"
not-null="true"
length="1"
/>
<property
name="omniType"
type="java.lang.String"
column="omni_type"
not-null="true"
length="1"
/>
The Dictionary mapping file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="com.maintenance.Dictionary"
table="dictionary"
>
<cache usage="read-only"/>

<composite-id name="comp_id" class="com.maintenance.Dictiona
ryPK">
<key-property
name="DictCode"
column="dict_code"
/>
<key-property
name="SubCode"
column="sub_code"
/>
</composite-id>

<property
name="codeDesc"
type="java.lang.String"
column="code_desc"
not-null="true"
length="30"
/>
<property
name="subDesc"
type="java.lang.String"
column="sub_desc"
not-null="true"
length="30"
/>
<property
name="updateUser"
type="java.lang.String"
column="update_user"
not-null="true"
length="12"
/>
<property
name="updateDate"
type="java.sql.Timestamp"
column="update_date"
not-null="true"
length="26"
/>

<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->


</class>
</hibernate-mapping>

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

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Ingres 2.6

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

I have following tables in a legacy database

There is table account which has account as a unique key. It also has other columns like account_type,name etc. There is table dictionary which has unique keys as dict_code and sub_code. There is a primary key class generated by middlegen for this releationship. The query for selecting all accounts is as foll:
select a.* from account a,dictionary b
where a.account_type=b.sub_code
and b.dict_code ='ACCT'
How do I define the relationship in the mapping so that I can avoid direct SQL? Is it possible or should I settle for createSQLQuery()?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 07, 2006 6:50 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
Can I use formula to achieve this?
In the account mapping file
<many-to-one class="Dictionary">
<formula>DictCode like 'ACCT_TYPE%' </formula>
</many-to-one>
Is this correct? It doesn't work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 11:38 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 3:44 pm
Posts: 26
I am guessing by the lack of response it is not possible. Solved it by using native SQL. Closed


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