-->
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.  [ 10 posts ] 
Author Message
 Post subject: @IdClass
PostPosted: Thu Apr 07, 2005 6:13 pm 
Newbie

Joined: Thu Apr 07, 2005 6:09 pm
Posts: 3
I've just downloaded and installed JBoss EJB 3 preview 5. I've been using preview 4 and now I'm getting a not yet implemented exception for @IdClass. This was working in preview 4 and not in preiew 5. What am I doing wrong>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 7:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Nothing, JBoss EJB3 now use Hibernate Annoations and this is not currently implemented.
Mainly because I don't think the @IdClass semantic is fully suported by Hibernate core right now.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: @IdClass
PostPosted: Fri Apr 08, 2005 8:16 am 
Newbie

Joined: Wed Apr 06, 2005 1:13 pm
Posts: 13
jlowcock wrote:
I've just downloaded and installed JBoss EJB 3 preview 5. I've been using preview 4 and now I'm getting a not yet implemented exception for @IdClass. This was working in preview 4 and not in preiew 5. What am I doing wrong>


Hi, i´m facing the same problem, the hibernate annotations not support the @IdClass annotation.

I´m waiting for a tip to how to outline this situation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 10:17 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
If you have an embedded composite PK using a class PK,

Code:
public Man {
  public ManPk id;
  ...
}


use @EmbeddedId (have a look at the doc for more infos)

On the contrary, if your class has embedded id properties refering a ManPk (which is the purpose of @IdClass)
Code:
public Man {
  public String manFirstName;
  public String manLastName;
  ...
}

public ManPk implements Serializable {
  ...
}


Then you can't map it yet, sorry :-(

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 10:47 am 
Newbie

Joined: Wed Apr 06, 2005 1:13 pm
Posts: 13
emmanuel wrote:
If you have an embedded composite PK using a class PK,

Code:
public Man {
  public ManPk id;
  ...
}


use @EmbeddedId (have a look at the doc for more infos)

On the contrary, if your class has embedded id properties refering a ManPk (which is the purpose of @IdClass)
Code:
public Man {
  public String manFirstName;
  public String manLastName;
  ...
}

public ManPk implements Serializable {
  ...
}


Then you can't map it yet, sorry :-(


All my project that uses hibernate 2.x use separate PK classes, and I now want to migrate to Hibernate 3 with annotations. Well, i see that i will need to wait for the final version. For your undestanding one of my my .hbm.xml is bellow, I think that the composite-id tag will be replaced by the @IdClass annotation right ?

Anyway, thanks for the attention.

<hibernate-mapping>
<class
name="br.com.venus.model.valueobjects.Menu_profileVO"
table="MENU_PROFILE"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="pk"
class="br.com.venus.model.valueobjects.Menu_profileKeyVO"
>
<key-property
name="id_menu"
type="integer"
column="id_menu"
/>

<key-property
name="id_permission"
type="integer"
column="id_permission"
/>

<key-property
name="id_profile"
type="integer"
column="id_profile"
/>

</composite-id>

<many-to-one
name="menu"
class="br.com.venus.model.valueobjects.MenuVO"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="id_menu"
/>

<many-to-one
name="permission"
class="br.com.venus.model.valueobjects.PermissionVO"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="id_permission"
/>

<property
name="permission_value"
type="string"
update="true"
insert="true"
access="property"
column="permission_value"
length="50"
not-null="false"
unique="false"
/>

<property
name="status"
type="integer"
update="true"
insert="true"
access="property"
column="status"
length="1"
not-null="false"
unique="false"
/>

<many-to-one
name="profile"
class="br.com.venus.model.valueobjects.ProfileVO"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="id_profile"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Menu_profileVO.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 10:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No this case works perfectly!
just use

Code:
public class Menu_profileVO {
@EmbeddedId
public Menu_profileKeyVO getPk() {}
}



The case that does not currently work is
Code:
<composite-id> <!-- no class neither name -->
<key-property
name="id_menu"
type="integer"
column="id_menu"
/>

<key-property
name="id_permission"
type="integer"
column="id_permission"
/>

<key-property
name="id_profile"
type="integer"
column="id_profile"
/>

</composite-id>


Actually, the @IdClass is not even possible with H3 hbm mappings

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 12:24 pm 
Newbie

Joined: Wed Apr 06, 2005 1:13 pm
Posts: 13
I had tried this a time ago.
Tried now with beta 1 and putting @EmbeddedId and get the following exception:

Annotated class should have an @Entity annotation: br.com.venus.model.valueobjects.Menu_profileKeyVO

Put the @Entity on the Menu_profileKeyVO class (@Entity (access = AccessType.PROPERTY)) and received the following exception :

13:12:50,652 ERROR [ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ludSessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NullPointerException: null
java.lang.NullPointerException
at org.hibernate.mapping.PersistentClass.createPrimaryKey(PersistentClass.java:266)

I think that i may not understanding something, bellow i put my spring config peace of code relative to the session factory and my 2 classes :

Spring configuration :

<!-- DataSource Definition -->
<bean id="ludDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/Venus</value>
</property>
</bean>

<!-- Hibernate SessionFactory Definition -->
<bean id="ludSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>WEB-INF/hibernate_configuration.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="dataSource">
<ref bean="ludDataSource"/>
</property>
</bean>


hibernate_configuration.xml :

<hibernate-configuration>


<session-factory>
<!-- properties -->
<property name="dialect">org.hibernate.dialect.FirebirdDialect</property>
<property name="show_sql">false</property>

<mapping package="br.com.venus.model.valueobjects"/>
<mapping class="br.com.venus.model.valueobjects.MenuVO"/>
<mapping class="br.com.venus.model.valueobjects.ProfileVO"/>
<mapping class="br.com.venus.model.valueobjects.Menu_profileVO"/>
<mapping class="br.com.venus.model.valueobjects.Menu_profileKeyVO"/>

</session-factory>

</hibernate-configuration>


MenuProfileVO :

@Entity (access = AccessType.PROPERTY)
@Table (name = "MENU_PROFILE")
public class Menu_profileVO implements Serializable {

private Menu_profileKeyVO pk;
private String permission_value;
private MenuVO menu;
private ProfileVO profile;
private PermissionVO permission;
private Integer status;

public Menu_profileVO() {
super();
}

@ManyToOne ( targetEntity = "br.com.venus.model.valueobjects.MenuVO" )
@JoinColumn ( name = "id_menu", insertable = false, updatable = false)
public MenuVO getMenu() {
return menu;
}

@ManyToOne ( targetEntity = "br.com.venus.model.valueobjects.PermissionVO" )
@JoinColumn ( name = "id_permission", insertable = false, updatable = false)
public PermissionVO getPermission() {
return permission;
}

@Column (name = "permission_value", nullable = true, length=50, unique = false)
public String getPermission_value() {
return permission_value;
}

@Column (name = "status", nullable = true, unique = false)
public Integer getStatus() {
return status;
}

@EmbeddedId
public Menu_profileKeyVO getPk() {
return pk;
}

@ManyToOne ( targetEntity = "br.com.venus.model.valueobjects.ProfileVO" )
@JoinColumn ( name = "id_profile", insertable = false, updatable = false)
public ProfileVO getProfile() {
return profile;
}

.....


Menu_profileKeyVO :

@Entity (access = AccessType.PROPERTY)
public class Menu_profileKeyVO implements Serializable {

private Integer id_menu;
private Integer id_profile;
private Integer id_permission;

public Menu_profileKeyVO() {
super();
}

@Column (name = "id_menu", nullable = true, unique = false)
public Integer getId_menu() {
return id_menu;
}

@Column (name = "id_permission", nullable = true, unique = false)
public Integer getId_permission() {
return id_permission;
}

@Column (name = "id_profile", nullable = true, unique = false)
public Integer getId_profile() {
return id_profile;
}

...

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Remove
Code:
<mapping class="br.com.venus.model.valueobjects.Menu_profileKeyVO"/>


A PK class is not an entity

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 1:11 pm 
Newbie

Joined: Wed Apr 06, 2005 1:13 pm
Posts: 13
emmanuel wrote:
Remove
Code:
<mapping class="br.com.venus.model.valueobjects.Menu_profileKeyVO"/>


A PK class is not an entity


Yes, it worked!!!

Certainly that i had missed something, now i can continue with my migration path.

Only one doubt, when i make this configuration with Hibernate2 I needed to put the PK mapping and worked, this was really necessary???

Thanks for the fast response and attention.

And congratulations for the great job at Hibernate!!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 5:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
rogerio.saulo wrote:
Only one doubt, when i make this configuration with Hibernate2 I needed to put the PK mapping and worked, this was really necessary???

No you sould not put it even in H2

_________________
Emmanuel


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