@MapKey produces invalid (postgresql-) sql output
-------------------------------------------------
Key: HHH-3805
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3805
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.2.6
Reporter: Alfons Name
I've got a couple of entities named basket, basketElement, item and alike. Most of
them carry an id attribute.
Trying to use the map as given in (1)
class Basket
...
@OneToMany(cascade = CascadeType.ALL, mappedBy = "basket")
@MapKey()
Map<Long, BasketElement> elements = new HashMap<Long, BasketElement>();
...
class BasketElement
@Id @Generated
Long id
@ManyToOne(optional = false)
Basket basket;
..
results in
select elements0_._BASKET as column5_7_, elements0_._ID as column1_7_,
_ID as formula1_7_,
elements0_._ID as column1_56_6_, elements0_._BASKET as column5_56_6_, elements0_._END as
column2_56_6_, elements0_._NUM_ITEM as column3_56_6_, elements0_._START as column4_56_6_,
elements0_1_._ITEM as column2_57_6_, elements0_2_._TYPE as column2_58_6_, case when
elements0_1_.id is not null then 1 when elements0_2_.id is not null then 2 when
elements0_._ID is not null then 0 end as clazz_6_, item1_._ID as column1_44_0_,
item1_._COMMENT as column2_44_0_, item1_._ITEMSET as column5_44_0_, item1_._NAME as
column3_44_0_, item1_._NUM_ITEMS as column4_44_0_, item1_._TYPE as column6_44_0_,
itemset2_._ID as column1_45_1_, itemset2_._NAME as column2_45_1_, type3_._ID as
column1_46_2_, type3_.name as name46_2_, type3_._PARENT as column3_46_2_, type4_._ID as
column1_46_3_, type4_.name as name46_3_, type4_._PARENT as column3_46_3_,
barcodeite5_.barcode as column1_41_4_, barcodeite5_._ITEM as column2_42_4_, type6_._ID as
column1_46_5_, type6_.name as name46_5_, type6_._PARENT as column3_46_5_ from
lager_BASKET_ELEMENT elements0_ left outer join lager_BASKET_ITEM elements0_1_ on
elements0_._ID=elements0_1_.id left outer join lager_BASKET_TYPE elements0_2_ on
elements0_._ID=elements0_2_.id left outer join lager_ITEM item1_ on
elements0_1_._ITEM=item1_._ID left outer join lager_ITEM_SET itemset2_ on
item1_._ITEMSET=itemset2_._ID left outer join lager_TYPE type3_ on item1_._TYPE=type3_._ID
left outer join lager_TYPE type4_ on type3_._PARENT=type4_._ID left outer join
lager_BARCODE_ITEM barcodeite5_ on item1_._ID=barcodeite5_._ITEM left outer join
lager_BARCODE barcodeite5_1_ on barcodeite5_.barcode=barcodeite5_1_._BARCODE left outer
join lager_TYPE type6_ on elements0_2_._TYPE=type6_._ID where elements0_._BASKET=?
and causes
...
Caused by: org.hibernate.exception.SQLGrammarException: could not initialize a collection:
[fem.lager.om.Basket.elements#4]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2001)
at
org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
at
org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
at
org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:63)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1716)
at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentMap.values(PersistentMap.java:234)
at fem.lager.om.Reservation.getStart(Reservation.java:28)
at
fem.lager.generator.DoReservationListGenerator.generate(DoReservationListGenerator.java:108)
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:544)
... 90 more
Caused by: org.postgresql.util.PSQLException: error: column »_id« is ambiguous.
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1592)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1327)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:192)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1994)
... 100 more
It looks very much like a bug and would be quite useful to have working.
(1)
http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#e...
AZ
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira