users@glassfish.java.net

Re: _at_ManyToOne when Foreign Key is also Primary Key

From: Gregory Gerard <ggerard_at_mac.com>
Date: Thu, 21 Oct 2010 07:31:09 -0700

D'oh! Don't know about JPA 1.0 techniques.

The attribute is just so I know when that association was made between the two records. I have other information on that relationship not shown such as who made the association as well.

Greg

On Oct 21, 2010, at 7:18, glassfish_at_javadesktop.org wrote:

> Hello, Gregory!
> Thanks a lot for the reply.
>
> Unfortunately, your solution didn't work to me.
>
> I've found that configuration (using @Id annotation with @ManyToOne) you've showed me in documentation for [b]JPA 2.0[/b], but, in my enviroment, I use Java Enterprise 5 with [b]JPA 1.0[/b].
>
> If I try configure my classes like using JPA 2.0 standard (your solution), I get the following error when I try deploy my solution:
>
> 09:36:58,753 ERROR [AbstractKernelController] Error installing to Start: name=persistence.unit:unitName=test.ear/test.dataaccess/classes#test.dataaccess state=Create
> org.hibernate.AnnotationException: Unable to find properties (idCard, idClient) in entity annotated with @IdClass:test.dataaccess.to.ClientCard
>
>
>
> Back to my initial configuration...
>
> I forgot about mention my PK class, but I do have one.
>
> So, here it comes again my classes:
>
> [b]Table Client[/b]
> cli_id_client (PK)
>
> [b]Table Card[/b]
> cli_id_card (PK)
>
> [b]Table ClientCard[/b]
> cli_id_client (PK)
> cli_id_card (PK)
>
>
> Those are my entities:
>
> @Entity(name = "ClientCard")
> @IdClass(ClientCardPK.class)
> @Table(name = "ClientCard")
> public class [b]ClientCard[/b]{
> @Id
> @Column(name = "car_id_card")
> private int idCard;
>
> @Id
> @Column(name = "cli_id_client")
> private int idClient;
>
> @ManyToOne(fetch = FetchType.LAZY)
> @PrimaryKeyJoinColumns({_at_PrimaryKeyJoinColumn(name = "car_id_card", referencedColumnName = "car_id_card")})
> private Card card;
>
> @ManyToOne(fetch = FetchType.LAZY)
> @PrimaryKeyJoinColumns({_at_PrimaryKeyJoinColumn(name = "cli_id_client", referencedColumnName = "cli_id_client")})
> private Client client;
>
> }
>
> public class [b]ClientCardPK[/b] {
> @Column(name = "cli_id_client")
> private long client;
> @Column(name = "car_id_card")
> private long card;
> }
>
> @Entity(name = "Client")
> @Table(name = "Client")
> public class [b]Client[/b]{
> @Id
> @Column(name = "cli_id_client")
> private int idClient;
>
> @OneToMany(mappedBy="client")
> private java.util.List<ClientCard> listClientCard;
> }
>
> @Entity(name = "Card")
> @Table(name = "Card")
> public class [b]Card[/b]{
> @Id
> @Column(name = "car_id_card")
> private int idCard;
>
> @OneToMany(mappedBy = "card")
> private java.util.List<ClientCard> listClientCard;
> }
>
>
>
> Other question: why is that @Temporal attribute for?
> [Message sent by forum member 'danilorocha']
>
> http://forums.java.net/jive/thread.jspa?messageID=485858
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>