-->
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.  [ 6 posts ] 
Author Message
 Post subject: [solved] mapping natural join on composite id
PostPosted: Fri Mar 07, 2008 7:21 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
Hello forumers,

I have two entitiy classes sharing a composite ID class. I would now like to map a OneToOne association that associates entities with equal database identity (i.e. a natural join on the primary key columns). Moreover, I want hibernate to generate lazy loading proxies for associated entities (the association is not nullable in any direction). How do I annotate the entities to accomplish that?

The reference documentation explains how to do a natural join on primary keys, but only for non-composite ones.

The bare bones of my code:

Code:
@Embeddable
public class InkassoFallImpl extends CompositeIdBase implements InkassoFall {
    @Column(name = "MI0100A")
    @Type(type = "ch.bedag.a7i.neskobz.domain.hibernate.usertype.ZPVNummerType")
    public ZPVNummer getZpvNummer() { }

    @Column(name = "MI0114A")
    @Type(type = "ch.bedag.a7i.neskobz.domain.hibernate.usertype.JahrType")
    public Jahr getSteuerjahr() { }

    @Column(name = "MI0104A")
    @Type(type = "RegisterDef")
    public Register getRegister() { }

    @Column(name = "MI0160A")
    @Type(type = "ch.bedag.a7i.neskobz.domain.hibernate.usertype.FallLaufnummerType")
    public FallLaufnummer getFallLaufnummer() { }
}


Code:
@javax.persistence.Entity
@Table(name = "A7IY112")
@Proxy(proxyClass = Saldo.class)
public class SaldoImpl extends VersionedEntityLegacyBase implements Saldo, ValidatingEntity {

    @javax.persistence.Id
    public InkassoFallImpl getInkassoFall() { }

    @OneToOne(targetEntity = InkassoAuftragImpl.class, fetch = FetchType.LAZY, optional = false)
    public InkassoAuftrag getInkassoAuftrag() { }
}


Code:
@javax.persistence.Entity
@Table(name = "A7IY011")
@Proxy(proxyClass = InkassoAuftrag.class)
public class InkassoAuftragImpl extends VersionedEntityLegacyBase implements InkassoAuftrag, ValidatingEntity {
    @javax.persistence.Id
    public InkassoFallImpl getInkassoFall() { }

    @OneToOne(targetEntity = SaldoImpl.class, fetch = FetchType.LAZY, //
    optional = false)
    public Saldo getSaldo() { }
}


How do I tell hibernate it's a natural join on the primary key?


Last edited by Adrian Moos on Mon Mar 17, 2008 9:57 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 7:27 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
What do I have to do to get an answer?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 7:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Adrian Moos wrote:
What do I have to do to get an answer?


http://www.hibernate.org/160.html

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 6:37 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
Could you be a bit more specific?

As far as I know, I did follow the guidelines, the free "Java Persistence with Hibernate" chapter and reference documentation contain nothing pertinent, my forum searches "composite id natural join", "join composite primary key" yielded many results, the first 10 of which where not relevant, the faq doesn't mention the problem, the hibernate log doesn't tell me the expected way to annotate these entities, source code analysis to reverse engineer the expected annotation proved too involved to bear fruit within half a day, I did isloate the problem, the debugger is useless because the problem is not an exception being thrown, and I have spent a day trying to resolve the problem on my own.

I think I gave as much information as relevant, but if not, please tell me what you need. I did format my post, did not blame hibernate nor insult its developers.

I keep trying to solve the problem, could live with an RTFM that gives me some clue where I missed something, I do entertain the possiblity it might have been my fault, and I do hope you do not consider my question what I did wrong "bumping" this thread.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 10:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I was merely referring that there is not timeline guaranty, nor even guaranty at all for that matter, on this forum.

Back to your problem, I think using
Code:
@PrimaryKeyJoinColumn
will work. I am not entirely sure though. Let me know.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 17, 2008 9:44 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
It does.


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