-->
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.  [ 1 post ] 
Author Message
 Post subject: @IdClass with @Ids pointing to non-primitive @ManyToOne
PostPosted: Sun Mar 22, 2009 12:04 pm 
Beginner
Beginner

Joined: Sat Feb 07, 2009 12:31 am
Posts: 21
Hi,

I'm trying to use @IdClass as composite key. But a lot of example used @IdClass pointing to a class with simple entities. Consider the following:

Code:
@Entity
@IdClass(AssignedRoleId.class)
public class AssignedRole
{
  @Id
  @ManyToOne
  private User userId;
 
  @Id
  @ManyToOne 
  private Role roleId;

  private Date dateAssigned;
}

public class AssignedRoleId
{
  private long userId;
  private long roleId;
}

other entities:
user ( id, username, password )
role (id, role, description )


This quite work but only one foreign key is generated (AssignedRole.userId), there's no generated foreign key for AssignedRole.role.

I can't use user and role as data type for members of AssignedRoleId because hibernate will generate tinyblob as the type of the column if I do.

Notice the name of members of AssignedRole, they're "userId" and "roleId" instead of "user" and "role", because I want those keys stored in the table AssignedRole as "userId" and "roleId". Even if you annotate it with @JoinColumn it will just get ignored. And by looking at the generated sql from "select as.user from AssignedRole as" it only returns a long value instead of an object, so an exception throws when you try "select as.user.username from AssignedRole as" because "as.user" is just a long value and not a user object.

Is the semantics that I want supported by hibernate? Or using @IdClass with @Id(s) with @ManyToOne is misusing hibernate?

Or, can I use non-primitive type as members of AssignedRoleId without letting hibernate generate a blob as the datatype of the column?

Thanks.

_________________
A good framework is hard to misuse or it's obvious when you misuse it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.