-->
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: Hibernate 3.2.5 bug with annotation @ManyToMany ???
PostPosted: Mon Jun 28, 2010 11:49 am 
Newbie

Joined: Thu Jun 24, 2010 1:29 pm
Posts: 2
Hello, i have the problem in mapping tables using annotation @ManyToMany in a specific situation.
When you have a many-to-many relationship between entities and you use relation table containing only of foreign keys to avoid many-to-many relationship in your DB. The relation table has only 2 columns which are foreign keys from related tables, and it forms composite primary key.
For example:
USR
pk:id
FUNCT_PERMISSION
pk:id
GRANTED_PERMISSION
uid
pid
pk:(uid,pid)

I am able to do correct mapping with hbm.xml configuration, also i am able to work arround and do annotations mapping by adding surrogate primary key to GRANTED_PERMISSION table, then my annotation mapping uses only @ManyToOne annotations And it works, but whenever it is @ManyToMany it throws error:
Quote:
org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: USR.Usr.functPermissions[USR.FunctPermission]
at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1068)
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:600)
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:541)
at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1130)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)

Note i am using Hibernate 3.2.5

I dont want to change DB cos in my DB i have 5 such situations and i dont want to use surrogate keys, and i dont want to use hbm.xml configurration i want to use annnotations.

My mappings are:
Usr.java
Code:
@ManyToMany(targetEntity=USR.FunctPermission.class, cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinTable(name="GRANTED_PERMISSION", schema="dbo", catalog="USER_RIGHTS", joinColumns = {
        @JoinColumn(name="USRID", nullable=false, updatable=false) }, inverseJoinColumns = {
        @JoinColumn(name="FPERMID", nullable=false, updatable=false) })
    public Collection<FunctPermission> getFunctPermissions() {
        return this.functPermissions;
    }

FunctPermission.java
Code:
@ManyToMany(mappedBy = "functPermissions", targetEntity= USR.Usr.class, cascade=CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinTable(name="GRANTED_PERMISSION", schema="dbo", catalog="USER_RIGHTS", joinColumns = {
        @JoinColumn(name="FPERMID", nullable=false, updatable=false) }, inverseJoinColumns = {
        @JoinColumn(name="USRID", nullable=false, updatable=false) })
    public Collection<Usr> getUsrs() {
        return this.usrs;
    }

hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;databaseName=USER_RIGHTS</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password">blahblah</property>
    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>
    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>
    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>
    <mapping class="USR.Helper"/>
    <mapping class="USR.Usr"/>
    <mapping class="USR.FunctPermission"/>
    <mapping class="USR.HibernateUtil"/>
  </session-factory>
</hibernate-configuration>

Is it Hibernate older version bug? Do i definetly need newer Hibernate version? How can i map correctly my classes with annotations, i am 3 days on it cannot find a reason. Help would be highly appreciated.


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.