-->
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.  [ 4 posts ] 
Author Message
 Post subject: MapKey error, when using a default schema name
PostPosted: Thu Jun 14, 2007 8:36 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Hello,

Using javax.persistence.MapKey with a one2many relation does not work, if I use a default schema name. the schema name is ignored when selecting the map column value with a subquery.
See the code below. my default schema was named annotation.

I suppose this is bug.

Best Regards

Sebastian Hennebrüder

Hibernate version:
hibernate-annotations-3.3.0.GA
Mapping documents:
Code:
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;

@Entity
public class Beach implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private String name;

    @MapKey(name = "isoCode")
    @OneToMany
    private Map<String, Country> countries = new HashMap<String, Country>();


Code:
import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="tcountry")
public class Country implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    private String isoCode;

    private String name;

Code between sessionFactory.openSession() and session.close():
Code:
List<Beach> beaches = session.createCriteria(Beach.class).list();
   for (Beach beach : beaches) {
       System.out.println(beach);
       for (String key : beach.getCountries().keySet()) {
      System.out.println(MessageFormat.format("{0} = {1}", new Object[] { key,
         beach.getCountries().get(key) }));
       }
   }

Full stack trace of any exception that occurs:
Code:
4:32:15,492 ERROR JDBCExceptionReporter:78 - FEHLER: Relation »tcountry« existiert nicht
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not initialize a collection: [de.laliluna.other.mapkey.Beach.countries#2]
   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:1992)
   at org.hibernate.loader.collection.BatchingCollectionInitializer.initialize(BatchingCollectionInitializer.java:52)
   at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:565)
   at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
   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.keySet(PersistentMap.java:226)

Name and version of the database you are using:

The generated SQL (show_sql=true):
Code:
select countries0_.Beach_id as Beach1_1_, countries0_.countries_id as countries2_1_,
(select a7.isoCode from tcountry a7
where a7.id=countries0_.countries_id) as formula1_1_,
country1_.id as id66_0_, country1_.isoCode as isoCode66_0_, country1_.name as name66_0_

from annotation.Beach_tcountry countries0_
left outer join annotation.tcountry country1_ on countries0_.countries_id=country1_.id where countries0_.Beach_id=?

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 10:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
the one to many has to be a mappedBy

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 11:15 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
It works, if I remove the default_schema property in hibernate.cfg.xml. It seems to work arbitrarily.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 5:51 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
ah
Unfortunately, there isn't much I can do easily on that. @MapKey does not support defaul schema or catalog definition

_________________
Emmanuel


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