[hibernate-issues] [Hibernate-JIRA] Resolved: (HHH-3939) @NotAudited association requires and joins to the associated table

Adam Warski (JIRA) noreply at atlassian.com
Fri Jun 5 08:26:13 EDT 2009


     [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-3939?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Adam Warski resolved HHH-3939.
------------------------------

         Assignee: Adam Warski
       Resolution: Fixed
    Fix Version/s: 3.5

> @NotAudited association requires and joins to the associated table
> ------------------------------------------------------------------
>
>                 Key: HHH-3939
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3939
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: envers
>         Environment: envers-1.2.0
> hibernate-3.3.1.ga
> hibernate-annotations-3.4.0.ga
> postgresql-8.1-407
>            Reporter: dsailer
>            Assignee: Adam Warski
>             Fix For: 3.5
>
>
> We have an Asset with an association to an Organization. Asset is audited and Organization is not. The association to Organization has @NotAudited. However, envers still requires the join table to exist. If the table exists AuditReader's queries for Asset revisions try to join to that table. Our work around was to go ahead and audit Organization. Here is the code:
> @Entity
> @Table(name = "MTE_ASSET")
> @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
> @Audited
> public class Asset extends AuditableEntity implements Serializable{
> <snip>
>    @ManyToOne
>    @JoinTable(name="mte_organization_mte_asset",
>               joinColumns = @JoinColumn(name="asset_id"),
>               inverseJoinColumns = @JoinColumn(name="organization_id"))
>    private Organization organization;
> <snip>
> }
> @Entity
> @Table(name = "MTE_ORGANIZATION")
> @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
> @DiscriminatorColumn(
>    name = "organization_type",
>    discriminatorType = DiscriminatorType.STRING
> )
> @DiscriminatorValue("Organization")
> public class Organization extends AuditableEntity {
> <snip>
>    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
>    @JoinTable(name = "mte_organization_mte_asset", joinColumns = @JoinColumn(name = "organization_id"), inverseJoinColumns = @JoinColumn(name = "asset_id"))
>    @OrderBy(value="name asc")
>    private List<Asset> assets = new ArrayList<Asset>();
> <snip>
> }
> without the table mte_organization_mte_asset_audit defined and using:
> <entry key="hibernate.hbm2ddl.auto" value="validate"/>
> we get:
> Caused by: org.hibernate.HibernateException: Missing table: mte_organization_mte_asset_audit
>         at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1113)
>         at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
>         at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:349)
>         at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
>         at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.jav
> a:867)
>         at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
> ... 38 more
> If we create the table mte_organization_mte_asset_audit but don't audit Organization the queries from AuditReader include a join to  mte_organization_mte_asset_audit and we get no rows back. 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list