-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Composite Ids
PostPosted: Thu Feb 05, 2009 5:51 am 
Newbie

Joined: Thu Feb 05, 2009 5:23 am
Posts: 3
Hi,

I have tried the Reverse Engineering with a composite key table. The generated POJO has a bean wrapper which represents the composite key.

I`ve already unchecked "generate basic typed composite ids" in order to not create the bean wrapper but it doesn´t work.

So is there any way to create POJOs with the keys as POJO's properties and not as a bean wrapper?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 8:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
check "generate basic typed composite ids" to not get the composite class.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 8:57 am 
Newbie

Joined: Thu Feb 05, 2009 5:23 am
Posts: 3
We've got checked all the options:
    Generate basic typed composite ids
    Detect optimistic lock columns
    Detect many-to-many tables
    Detect one-to-one associations


The table has got composite key:
Table name: Item
int id1 (Primary Key)
int id2 (Primary Key)
varchar(100) value

And Hibernate Tool creates the following classes:
class Item {
private ItemId id;
private String value;
}

class ItemId {
private int id1;
private int id2;
}

But I would like to obtain this:
class Item{
private int id1;
private int id2;
private String value;
}

With the 'generate basic typed composite ids' options checked or unchecked I get the same result, the wrapper bean for the id. Can I avoid the id wrapper?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 8:58 am 
Newbie

Joined: Thu Feb 05, 2009 5:23 am
Posts: 3
We've got checked all the options:
    Generate basic typed composite ids
    Detect optimistic lock columns
    Detect many-to-many tables
    Detect one-to-one associations


The table has got composite key:
Table name: Item
int id1 (Primary Key)
int id2 (Primary Key)
varchar(100) value

And Hibernate Tool creates the following classes:
class Item {
private ItemId id;
private String value;
}

class ItemId {
private int id1;
private int id2;
}

But I would like to obtain this:
class Item{
private int id1;
private int id2;
private String value;
}

With the 'generate basic typed composite ids' options checked or unchecked I get the same result, the wrapper bean for the id. Can I avoid the id wrapper?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 10:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah sorry, i mixed up the option. That option just chooses to use prmitives in the case that the key is a foreignkey to another entity.

About the composite class, then no, we don't have an option for "flatten" that hierarchy since that has many issues associated with it + noone came up with a reason why you would not want it.

Do you got a good usecase ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: If we can't disable the creation of composit ids then how?
PostPosted: Fri Mar 06, 2009 1:24 pm 
Newbie

Joined: Fri Mar 06, 2009 1:20 pm
Posts: 7
Location: wayne, pa
If you generate composite keys, then I can't figure out how to use named queries that use the composite key....If "system_name is part of the composite id then you get a message not all named paramaters have values.....that is becuase it tries to call a getter for system_name and system_name is under getId().getSystemName

where system_name = :system_name


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 06, 2009 7:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
id.system_name = :system_name

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Got additional error
PostPosted: Mon Mar 09, 2009 11:17 am 
Newbie

Joined: Fri Mar 06, 2009 1:20 pm
Posts: 7
Location: wayne, pa
Errors in named queries: getStgIdentifier

The named query is:

<query name="getStgIdentifier">
FROM IcvStgIdentifierT
WHERE Id.SOURCE_SYSTEM_NAME = :sourceSystemName
AND SOURCE_SYSTEM_KEY_NAME = :sourceSystemKeyName
AND SOURCE_SYSTEM_KEY_VALUE= :sourceSystemKeyValue
ORDER BY decode(RECORD_ACTION,'D',1,2)
</query>

The hbm xml is:
<class name="com.delagelanden.icv.stg.hibernate.IcvStgIdentifierT" table="ICV_STG_IDENTIFIER_T">
<composite-id name="id" class="com.delagelanden.icv.stg.hibernate.IcvStgIdentifierTId" >
<key-property name="sourceSystemName" type="string">
<column name="SOURCE_SYSTEM_NAME" length="50" />
</key-property>
<key-property name="recordNumber" type="big_integer">
<column name="RECORD_NUMBER" scale="0" />
</key-property>
</composite-id>
<property name="recordAction" type="string">
<column name="RECORD_ACTION" length="1" not-null="true" />
</property>
...

Thanks for your help so far.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 09, 2009 4:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
And what does the log contains ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: log messages
PostPosted: Tue Mar 10, 2009 11:09 am 
Newbie

Joined: Fri Mar 06, 2009 1:20 pm
Posts: 7
Location: wayne, pa
DEBUG [11:07:16] icv.batch.common.AbstractBatchController Run process [MAINTAIN_PARTY]
ERROR [11:08:10] org.hibernate.impl.SessionFactoryImpl Error in named query: getStgIdentifier
org.hibernate.QueryException: could not resolve property: id.SOURCE_SYSTEM_NAME of: com.delagelanden.icv.stg.hibernate.IcvStgIdentifierT [
FROM com.delagelanden.icv.stg.hibernate.IcvStgIdentifierT
WHERE id.SOURCE_SYSTEM_NAME = :sourceSystemName
AND SOURCE_SYSTEM_KEY_NAME = :sourceSystemKeyName
AND SOURCE_SYSTEM_KEY_VALUE= :sourceSystemKeyValue
ORDER BY decode(RECORD_ACTION,'D',1,2)
]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:59)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1354)
at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:315)
at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:290)
at org.hibernate.hql.ast.tree.FromElement.toColumns(FromElement.java:390)
at org.hibernate.hql.ast.tree.DotNode.getColumns(DotNode.java:111)
at org.hibernate.hql.ast.tree.DotNode.initText(DotNode.java:230)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:205)
at org.hibernate.hql.ast.tree.DotNode.resolveFirstChild(DotNode.java:153)
at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:459)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4326)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1212)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4041)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3525)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:413)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:361)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1304)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:901)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:827)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:957)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:924)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:415)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:239)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:155)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:297)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:348)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
at com.dll.icv.batch.common.AbstractBatchController.initApplicationContext(AbstractBatchController.java:149)
at com.dll.icv.batch.common.AbstractBatchController.initialize(AbstractBatchController.java:131)
at com.dll.icv.batch.common.AbstractBatchController.<init>(AbstractBatchController.java:105)
at com.dll.icv.batch.common.ChunkBatchController.<init>(ChunkBatchController.java:36)
at com.dll.icv.batch.common.BatchDriver.process(BatchDriver.java:90)
at com.dll.icv.batch.common.BatchDriver.main(BatchDriver.java:64)
ERROR [11:08:10] com.dll.icv.batch.common.BatchDriver org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactoryForBatch' defined in class path resource [com/dll/icv/batch/config/icv_batch_config.xml]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Errors in named queries: getStgIdentifier


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 12:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are using column names where you should be using property names.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: new error
PostPosted: Wed Mar 11, 2009 9:35 am 
Newbie

Joined: Fri Mar 06, 2009 1:20 pm
Posts: 7
Location: wayne, pa
ERROR [09:33:08] dll.icv.batch.proxy.hibernate.BatchProxy Could not load data by named query
org.hibernate.QueryException: Not all named parameters have been set: [sourceSystemName] [
FROM IcvStgIdentifierT
WHERE id.sourceSystemName = :sourceSystemName
AND SOURCE_SYSTEM_KEY_NAME = :sourceSystemKeyName
AND SOURCE_SYSTEM_KEY_VALUE= :sourceSystemKeyValue
ORDER BY decode(RECORD_ACTION,'D',1,2)
]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:291)
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:275)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:75)
at com.dll.icv.batch.proxy.hibernate.BatchProxy.retrieve(BatchProxy.java:153)
at com.dll.icv.batch.process.party.MaintainPartyBatchProcess.populateParty(MaintainPartyBatchProcess.java:184)
at com.dll.icv.batch.process.party.MaintainPartyBatchProcess.processParty(MaintainPartyBatchProcess.java:75)
at com.dll.icv.batch.process.party.MaintainPartyBatchProcess.process(MaintainPartyBatchProcess.java:59)
at com.dll.icv.batch.common.AbstractBatchProcess.run(AbstractBatchProcess.java:57)


Top
 Profile  
 
 Post subject: new error
PostPosted: Wed Mar 11, 2009 9:50 am 
Newbie

Joined: Fri Mar 06, 2009 1:20 pm
Posts: 7
Location: wayne, pa
ERROR [09:33:08] dll.icv.batch.proxy.hibernate.BatchProxy Could not load data by named query
org.hibernate.QueryException: Not all named parameters have been set: [sourceSystemName] [
FROM IcvStgIdentifierT
WHERE id.sourceSystemName = :sourceSystemName
AND SOURCE_SYSTEM_KEY_NAME = :sourceSystemKeyName
AND SOURCE_SYSTEM_KEY_VALUE= :sourceSystemKeyValue
ORDER BY decode(RECORD_ACTION,'D',1,2)
]
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:291)
at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:275)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:75)
at com.dll.icv.batch.proxy.hibernate.BatchProxy.retrieve(BatchProxy.java:153)
at com.dll.icv.batch.process.party.MaintainPartyBatchProcess.populateParty(MaintainPartyBatchProcess.java:184)
at com.dll.icv.batch.process.party.MaintainPartyBatchProcess.processParty(MaintainPartyBatchProcess.java:75)
at com.dll.icv.batch.process.party.MaintainPartyBatchProcess.process(MaintainPartyBatchProcess.java:59)
at com.dll.icv.batch.common.AbstractBatchProcess.run(AbstractBatchProcess.java:57)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 11, 2009 2:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you are still using column an instead of property and that error should only be shown in context of a query.list() operation and you haven't shown that code.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: error
PostPosted: Wed Mar 11, 2009 3:04 pm 
Newbie

Joined: Fri Mar 06, 2009 1:20 pm
Posts: 7
Location: wayne, pa
maybe it will be fixed in a new release some day.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.