-->
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: JPA Hibernate 3 AuditJoinTable inversed relation question
PostPosted: Thu Dec 26, 2013 4:49 am 
Newbie

Joined: Thu Dec 26, 2013 4:43 am
Posts: 1
Hi,

Marry X'mas :)

I'm stuck with creating audit tables. I have two collections one-to-many relationships. Once is inverse, other one is not. The auditjointable annotation works for non-inversed relation but not for the inversed one. Here's my code.

Department class
Code:
@Entity
@Audited
@AuditTable(value = "DDD")
public class Department {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    @Audited
    private int id;
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
    private String name;

    @OneToMany(targetEntity = Professor.class,cascade = CascadeType.ALL)
    @JoinColumn(name = "dept_id")
    @AuditJoinTable(name = "abc")
    private java.util.Collection<Professor> employees;

    @OneToMany(targetEntity = Address.class, mappedBy = "department")<==inverse relation
    @AuditJoinTable(name = "def")
//I tried commenting this out and let the inverse side AuditJoinTable annotation, no luck
    private java.util.Collection<Address> addresses;
//Getters and setters remove to reduce clutter
}


Address class
Code:
    @Entity
    @Audited
    public class Address {
        @Id
        @GeneratedValue(strategy= GenerationType.IDENTITY)
        private int id;
        @Column
        private String name;

        @ManyToOne(cascade = CascadeType.ALL)
        @AuditJoinTable(name = "def")
        private Department department;


Professor
Code:
@Entity
@Audited
public class Professor {
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private int id;
    @Column
    private String name;
    private long salary;

    @ManyToOne
    @JoinColumn(name = "dept_id")
    private Department department;

}


When I create the scema using hibernate.hbm2ddl.auto "def" autdit table is not generated. However "abc" audit jointable is generated and when the employees collection is updated the audit entries are logged.
I'm using hibernate/hibernate-envers - 3.6.9.Final JPA 1.0
Tested with hibernate 4 as well no luck.

Did more investigations and added my own AuditEventListener and debuged initialize(Configuration cfg) method. It seems configuration does contain the non-inverse side audit table but not the inverse side audit table (along with may other info). So it seems like I'm annotating it wrong (or bug in annotation ?)

Any pointers 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.