-->
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: Do metamodel generation depends on environment ?
PostPosted: Fri Apr 19, 2013 9:08 am 
Newbie

Joined: Tue Mar 02, 2010 1:33 pm
Posts: 2
Hello there,

Not sure if posting in the correct section as my problem is mostly related to hibernate-jpamodelgen.

Anyway, here is the problem.
I got an Eclipse project using JPA configured to generate static metamodel with the hibernate-jpamodelgen library.

It appears that one of the generated classes contains an error, related to generic types. It makes my project unable to compile.
But what is strange, is when I generate the metamodel with maven, the error is gone, as the generic types are correctly processed.

Here is the setup

An JOINED inheritance of a generic AbstractItem<F, V> defined by an IItem<F,V> interface:

Code:
public interface IItem<F, V> {
   F getField();
   void setField(F field);
   V getValue();
   void setValue(V value);   
}


The AbstractItem<F,V> implementation:
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class AbstractItem<F, V> implements IItem<F, V>{

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private int id;

   @ManyToMany(mappedBy = "items", fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST })
   private Set<Holder> entities = new HashSet<Holder>();
   
   /* getters & setters */
}


An implementation of this Item:
Code:
@Entity
public class Item extends AbstractItem<String, Long> {

   @Basic
   private String field;

   @Basic
   private Long value;

   /* getters & setters impl */
}


And finally, an object Holder that hold a Set of AbstractItem<?,?> which is an @Entity:
Code:
@Entity
public class Holder {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private int id;

   @ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST })
   private Set<AbstractItem<?, ?>> items = new HashSet<AbstractItem<?,?>>();
   
   public Holder(){
      super();
   }
   
   /* getters & setters */
}


The problem appear with the static metamodel of the Holder class generated by eclipse APT which looks like this:

Code:
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(Holder.class)
public abstract class Holder_ {

   public static volatile SingularAttribute<Holder, Integer> id;
   public static volatile SetAttribute<Holder, AbstractItem<F,V>> item;

}

You can see that the second attribute declares unknown types (<F,V>), which lead to a compile error.

But, when generating the metamodel with maven, it is correctly done, as it removes the unknown types :
Code:
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(Holder.class)
public abstract class Holder_ {

   public static volatile SingularAttribute<Holder, Integer> id;
   public static volatile SetAttribute<Holder, AbstractItem> item;

}


It is quite a problem as this could change the workflow of our development team if no workaround is found, and I would really like to keep this JPA mapping, as it allows a real object inheritance through JPA.

I even tried checking out the latest sources of the hibernate-jpamodelgen lib, adding a test case for this setup, but the result were correct.

What do you think could cause such a difference ?
I can only see a different execution environment of the library between Eclipse APT and maven, but I don't know what to do to correctly configure eclipse to do it.

Thank you for taking the time to read me.

Environment details:
- Updated Eclipse Juno 4.2
- hibernate-jpamodelgen-1.2.0.Final & hibernate-jpamodelgen-1.3.0-SNAPSHOT
- hibernate-core-4.1.2.Final
- hibernate-jpa-2.0-api-1.0.1.Final
- JDK 1.6.0_45


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.