-->
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.  [ 12 posts ] 
Author Message
 Post subject: More composite-id fu!
PostPosted: Thu Sep 04, 2003 10:43 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I'm still trying to create the ID scheme laid out here: http://forum.hibernate.org/viewtopic.php?t=61

I'm so close to finishing I can taste it. :) Unfortunately I've come upon a glitch I can't seem to get around.


The problem is that when I try to put a many-to-one relationship in the ID, whether I use a custom id or composite-id with a key-many-to-one attribute, I get a net.sf.hibernate.MappingException.

Mapping:
Code:
<composite-id unsaved-value="any">
  <key-property name="id" type="long"/>
  <key-many-to-one name="site" class="com.foo.bar.data.sites.Site"/>
</composite-id>


Exception thrown at runtime:
Code:
net.sf.hibernate.MappingException: No persister for: com.foo.bar.data.sites.Site
        at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:337)
        at net.sf.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:472)
        at net.sf.hibernate.type.ManyToOneType.getColumnSpan(ManyToOneType.java:21)
        at net.sf.hibernate.type.ComponentType.getColumnSpan(ComponentType.java:58)
        at net.sf.hibernate.persister.NormalizedEntityPersister.<init>(NormalizedEntityPersister.java:719)
        at net.sf.hibernate.persister.PersisterFactory.create(PersisterFactory.java:32)
        at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:141)
        at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:657)
        at com.foo.bar.data.access.DataAccess.makeSessionFactory(DataAccess.java:70)
        at com.foo.bar.data.access.DataAccess.<clinit>(DataAccess.java:22)
        at HibernateTest.main(HibernateTest.java:102)


When I have a custom ID type I get the same exception with

Code:
at net.sf.hibernate.type.CompositeCustomType.getColumnSpan(CompositeCustomType.java:122)

instead of
Code:
at net.sf.hibernate.type.ComponentType.getColumnSpan(ComponentType.java:58)


The mapping for Site is in the same mapping file as the problem class, so I know it's loaded. Also, I can have a normal many-to-one tag in the same class without problems.

I think this may be related to a recent issue logged in JIRA: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?id=10331

The issue is marked closed and fixed, but the atteched comments seem to indicate that there are still problems.

Except in cases where I have custom types, I'n generating all java code and DDL from the mapping file.

I'm using version 2.1 beta 2.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 10:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is nothing to do with that JIRA issue.

It really looks like the associated class is not mapped.

submit something to JIRA is you are absolutely certain you can't resolve it yourself. I'm pretty certain it is error on your part.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 10:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
What happens if you reverse the order of the two mappings in the mapping file?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 11:26 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
No change if I change the order of the classes in the mapping file.

In all cases, I get the following log line:
Code:
22:13:39,288  INFO Binder:183 - Mapping class: com.foo.bar.data.sites.Site -> sites


The class is mapped. Like I said, I can have the following line in the mapping with no problem:
Code:
<many-to-one name="foo" class="com.foo.bar.data.sites.Site"/>


Also, when I use the <composite-id> method, the java code for the ID'd class is generated and the DDL for the underlying table (and all tables that refer to it) are generated just fine. I can call "new Configuration().configure()" just fine, but when I try to create a SessionFactory the problem pops up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 11:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Alright. Give me a main() method. (JIRA)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 1:40 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Done: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-311


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 5:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I ran your code against my snapshots of Hibernate 2.0 and 2.1 and no errors at all. Successfully persisted and retrieved a Site and SiteDataObject.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 12:50 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Are your snapshots any different from the currently released 2.1beta2 in the classes/methods from the stack trace above?

Also, did you use log4j for logging? Odd question, I know, but like I said in JIRA posting, when I took log4j.jar out of the classpath and commons-logging fell back to it's defaut configuration, I had no problems. (Only running the demonstration from the command line, though, not from ant.)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 12:51 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
And, I forgot to say, thanks a whole heap for your work. :D


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 9:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK, I managed to reproduce it now. I'll take a closer look.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 10:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Fixed in 2.1 and 2.0 branches.

A one line change, heres the diff


diff -r1.32.2.17 NormalizedEntityPersister.java
755c755
< int idColumnSpan = getIdentifierType().getColumnSpan(factory);
---
> int idColumnSpan = super.getIdentifierColumnNames().length;


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 8:21 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
d00d, you r0xr! :)


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