-->
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: Question about derived properties
PostPosted: Mon Jun 20, 2005 8:24 pm 
Newbie

Joined: Thu Apr 28, 2005 3:14 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5

Mapping documents:

1. Partners.hbm.xml as below:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="model">
<class
name="Partner"
table="PARTNERS"
>
<id
name="id"
type="integer"
column="PID"
>
<generator class="PidGenerator"/>
</id>

<timestamp
name="lastChanged"
column="LAST_CHANGED"
/>
<property
name="name"
column="NAME"
type="string"
not-null="true"
length="64"
/>
<set
name="vendors"
lazy="true"
inverse="true"
cascade="save-update"
>
<property name="defaultVendorId"
formula="(select vendor.VID from Partner partner join partner.vendors where vendors.name = NAME)"
type="integer"
/>
</class>
</hibernate-mapping>

2. Vendors.hbm.xml as below:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="model">
<class
name="Vendor"
table="VENDORS"
>
<id
name="id"
type="integer"
column="VID"
>
<generator class="VidGenerator"/>
</id>

<timestamp
name="lastChanged"
column="LAST_CHANGED"
/>
<property
name="name"
column="NAME"
type="string"
not-null="true"
length="64"
/>
<many-to-one
name="partner"
class="Partner"
column="PID"
cascade="save-update"
unique="true"
not-null="true"
/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Partner partner = session.load (new Integer(1024));

Full stack trace of any exception that occurs:
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC driver: Oracle JDBC driver, version: 9.2.0.4.0
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.dialect.Dialect> Using dialect: org.hibernate.dialect.Oracle9Dialect
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.transaction.TransactionFactoryFactory> Using default transaction strategy (direct JDBC transactions)
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.transaction.TransactionManagerLookupFactory> No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Automatic flush during beforeCompletion(): disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Automatic session close at end of transaction: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC batch size: 15
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC batch updates for versioned data: enabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Scrollable result sets: enabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC3 getGeneratedKeys(): disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Connection release mode: null
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Default schema: PAY
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Maximum outer join fetch depth: 1
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Default batch fetch size: 8
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Generate SQL with comments: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Order SQL updates by primary key: enabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO 06/20/2005 17:16:49 <Main Thread> <hql.ast.ASTQueryTranslatorFactory> Using ASTQueryTranslatorFactory
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Query language substitutions: {}
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Second-level cache: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Query cache: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Optimize cache for minimal puts: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Structured second-level cache entries: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Echoing all SQL to stdout
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Statistics: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Deleted entity synthetic identifier rollback: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Default entity-mode: pojo
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.impl.SessionFactoryImpl> building session factory
INFO 06/20/2005 17:17:00 <Main Thread> <hibernate.impl.SessionFactoryObjectFactory> Not binding factory to JNDI, no JNDI name configured
INFO 06/20/2005 17:17:00 <Main Thread> <hibernate.impl.SessionFactoryImpl> Checking 0 named queries
DEBUG 06/20/2005 17:17:01 <Main Thread> <org.hibernate.SQL> select partner0_.PID as PID, partner0_.LAST_CHANGED as LAST2_11_, partner0_.NAME as NAME11_, (select vendor.VID from Vendor vendor join vendor.partner partner where vendor.name = partner0_.NAME and partner.name=partner0_.NAME) as formula0_ from PAY.PARTNERS partner0_ where partner0_.PID=1026
WARN 06/20/2005 17:17:04 <Main Thread> <hibernate.util.JDBCExceptionReporter> SQL Error: 905, SQLState: 42000
ERROR 06/20/2005 17:17:04 <Main Thread> <hibernate.util.JDBCExceptionReporter> ORA-00905: missing keyword

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
select partner0_.PID as PID, partner0_.LAST_CHANGED as LAST2_11_, partner0_.NAME as NAME11_, (select vendor.VID from Vendor vendor join vendor.partner where vendor.name = partner0_.NAME and partner.name = partner0_NAME) as formula0_ from PAY.PARTNERS partner0_ where partner0_.PID=1026

Debug level Hibernate log excerpt:

Basically, I have a 2 hbm mappings, one for partner and other for partner's vendors. There's a one-to-many relationship between partner and vendor. Partner id (PID) and name is unique. Vendor Id (VID) is unique, vendor name is unique across a partner, but not across all the partners in the system. So partner name can identify a unique partner in the system whereas partnername+vendorname uniquely identifies a vendor in the system,
Each partner is also a vendor, with vendorname for this vendor (default vendor for partner) set to the partner name.

I am trying to load the default vendor for each partner as partner object is loaded using derived properties and am encountering error listed above.
Can anyone let me know what is missing in the formula or if it is correctly specified.

Thanks.


Top
 Profile  
 
 Post subject: Re: Question about derived properties
PostPosted: Tue Jun 21, 2005 9:11 pm 
Newbie

Joined: Thu Jun 16, 2005 9:03 pm
Posts: 1
<property name="defaultVendorId"
formula="(select vendor.VID from Partner partner join partner.vendors where vendors.name = NAME and partner.name = NAME)"
type="integer"
/>

Inside the formula attribute hibernate query language(HQL) can't be used so it should be replaced by SQL query. It can be rewritten as :

<property name="defaultVendorId"
formula="(select vendor.VID from Partner partner,Vendors vendor where vendor.name = NAME and partner.name = NAME)"
type="integer"
/>


Thanks!!
Abhishek

[quote="adalvi"]Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

[b]Hibernate version:[/b]
3.0.5

[b]Mapping documents:[/b]

1. Partners.hbm.xml as below:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="model">
<class
name="Partner"
table="PARTNERS"
>
<id
name="id"
type="integer"
column="PID"
>
<generator class="PidGenerator"/>
</id>

<timestamp
name="lastChanged"
column="LAST_CHANGED"
/>
<property
name="name"
column="NAME"
type="string"
not-null="true"
length="64"
/>
<set
name="vendors"
lazy="true"
inverse="true"
cascade="save-update"
>
<property name="defaultVendorId"
formula="(select vendor.VID from Partner partner join partner.vendors where vendors.name = NAME)"
type="integer"
/>
</class>
</hibernate-mapping>

2. Vendors.hbm.xml as below:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="model">
<class
name="Vendor"
table="VENDORS"
>
<id
name="id"
type="integer"
column="VID"
>
<generator class="VidGenerator"/>
</id>

<timestamp
name="lastChanged"
column="LAST_CHANGED"
/>
<property
name="name"
column="NAME"
type="string"
not-null="true"
length="64"
/>
<many-to-one
name="partner"
class="Partner"
column="PID"
cascade="save-update"
unique="true"
not-null="true"
/>
</class>
</hibernate-mapping>

[b]Code between sessionFactory.openSession() and session.close():[/b]
Partner partner = session.load (new Integer(1024));

[b]Full stack trace of any exception that occurs:[/b]
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC driver: Oracle JDBC driver, version: 9.2.0.4.0
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.dialect.Dialect> Using dialect: org.hibernate.dialect.Oracle9Dialect
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.transaction.TransactionFactoryFactory> Using default transaction strategy (direct JDBC transactions)
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.transaction.TransactionManagerLookupFactory> No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Automatic flush during beforeCompletion(): disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Automatic session close at end of transaction: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC batch size: 15
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC batch updates for versioned data: enabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Scrollable result sets: enabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> JDBC3 getGeneratedKeys(): disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Connection release mode: null
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Default schema: PAY
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Maximum outer join fetch depth: 1
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Default batch fetch size: 8
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Generate SQL with comments: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Order SQL updates by primary key: enabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO 06/20/2005 17:16:49 <Main Thread> <hql.ast.ASTQueryTranslatorFactory> Using ASTQueryTranslatorFactory
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Query language substitutions: {}
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Second-level cache: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Query cache: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Optimize cache for minimal puts: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Structured second-level cache entries: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Echoing all SQL to stdout
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Statistics: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Deleted entity synthetic identifier rollback: disabled
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.cfg.SettingsFactory> Default entity-mode: pojo
INFO 06/20/2005 17:16:49 <Main Thread> <hibernate.impl.SessionFactoryImpl> building session factory
INFO 06/20/2005 17:17:00 <Main Thread> <hibernate.impl.SessionFactoryObjectFactory> Not binding factory to JNDI, no JNDI name configured
INFO 06/20/2005 17:17:00 <Main Thread> <hibernate.impl.SessionFactoryImpl> Checking 0 named queries
DEBUG 06/20/2005 17:17:01 <Main Thread> <org.hibernate.SQL> select partner0_.PID as PID, partner0_.LAST_CHANGED as LAST2_11_, partner0_.NAME as NAME11_, (select vendor.VID from Vendor vendor join vendor.partner partner where vendor.name = partner0_.NAME and partner.name=partner0_.NAME) as formula0_ from PAY.PARTNERS partner0_ where partner0_.PID=1026
WARN 06/20/2005 17:17:04 <Main Thread> <hibernate.util.JDBCExceptionReporter> SQL Error: 905, SQLState: 42000
ERROR 06/20/2005 17:17:04 <Main Thread> <hibernate.util.JDBCExceptionReporter> ORA-00905: missing keyword

[b]Name and version of the database you are using:[/b]
Oracle 9i

[b]The generated SQL (show_sql=true):[/b]
select partner0_.PID as PID, partner0_.LAST_CHANGED as LAST2_11_, partner0_.NAME as NAME11_, (select vendor.VID from Vendor vendor join vendor.partner where vendor.name = partner0_.NAME and partner.name = partner0_NAME) as formula0_ from PAY.PARTNERS partner0_ where partner0_.PID=1026

[b]Debug level Hibernate log excerpt:[/b]

Basically, I have a 2 hbm mappings, one for partner and other for partner's vendors. There's a one-to-many relationship between partner and vendor. Partner id (PID) and name is unique. Vendor Id (VID) is unique, vendor name is unique across a partner, but not across all the partners in the system. So partner name can identify a unique partner in the system whereas partnername+vendorname uniquely identifies a vendor in the system,
Each partner is also a vendor, with vendorname for this vendor (default vendor for partner) set to the partner name.

I am trying to load the default vendor for each partner as partner object is loaded using derived properties and am encountering error listed above.
Can anyone let me know what is missing in the formula or if it is correctly specified.

Thanks.[/quote][quote][/quote]


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.