3

I'm using Eclipse build-in feature to generate JPA metamodel in my projects. Previosly it was generated perfectly, but after that something happened and now my metamodel classes are generated incomplete/wrong. Please note, that entity classes themselves didn't change a bit.
That's how it was generated just a few months ago:

@Generated(value="Dali", date="2014-03-03T15:27:31.931+0200")
@StaticMetamodel(AsmensZyma.class)
public class AsmensZyma_ {
    public static volatile SingularAttribute<AsmensZyma, Long> id;
    public static volatile SingularAttribute<AsmensZyma, Asmuo> asmuo;
    public static volatile SingularAttribute<AsmensZyma, AsmensZymaSource> registas;
    public static volatile SingularAttribute<AsmensZyma, Date> data;
    public static volatile SingularAttribute<AsmensZyma, String> roik;
    public static volatile SingularAttribute<AsmensZyma, String> pastaba;
}

And how it is being generated now:

@Generated(value="Dali", date="2014-05-30T11:48:56.816+0300")
@StaticMetamodel(AsmensZyma.class)
public class AsmensZyma_ {
   public static volatile SingularAttribute<AsmensZyma, Long> id;
   public static volatile SingularAttribute<AsmensZyma, Object> asmuo;
}

Note that there are plenty of missing fields, and fields types are not detected properly. This happens TO ALL my entity classes in ALL my projects... What I have tried so far:

  • Upgrading STS (currently using 3.5.1)
  • Cleaning/refreshing/updating projects
  • Re-configuring JPA metamodel generation in STS
  • Creating brand new clean workspace and importing only one project to it

Nothing helps so far...
Any suggestions or help is highly appretiated!

mabi
  • 5,279
  • 2
  • 43
  • 78
Serzhas
  • 854
  • 12
  • 23
  • This seems odd. The metamodel is generated by Dali, the Eclipse JPA tooling plug-in. You could open the Dali views (JPA Structure and JPA Details) and see whether your JPA mappings are displayed correctly. That might give us some hint as to whether and why Dali's model is corrupt. – Brian Vosburgh May 30 '14 at 16:48
  • Thanks! I will try and analyze aforementioned views. Will post my findings. – Serzhas Jun 02 '14 at 07:14
  • I have checked JPA Structure/Details views and found out, that all missing columns are treated as "unmapped". But they all are annotated with Column, why so? And ManyToOne relation is picked properly, however, generated metamodel lacks proper generic type anyway... – Serzhas Jun 02 '14 at 08:03
  • Hmmmm. It sounds like a Dali bug; but not one I have seen before. Can you try to load one of your simpler projects into a standard Eclipse Java EE (i.e. non-STS) workspace? It might isolate whether the problem is with Dali itself or its behavior inside of STS. – Brian Vosburgh Jun 04 '14 at 02:08
  • I'll download stand-alone Eclipse and will try. Thanks for suggestion. – Serzhas Jun 05 '14 at 08:58
  • @Serzhas did you find out what was causing this? I have the same issue – DaveB May 15 '15 at 12:39
  • Unfortunately, no. Problem is still there. I'm usually just add new fields manually. You can generate metamodel using Maven or similar method and then copy generated classes to source folder. Also, my colleague recently found another method, which is using hibernate-jpamodelgen.jar. This solution works perfectly in his project, however, in mine I'm getting scary Eclipse-level AspectJ error and nothing I've tried so far solves the problem. But it's worth a try for you, I think :) You need to specify custom annotation processor (which is aforementioned jar is) in your project configuration. – Serzhas May 16 '15 at 14:52

1 Answers1

0

Using Dali is one way, but you could just try using the metamodel generator of one of the JPA implementations itself. For example I use DataNucleus JPA and follow this page

http://www.datanucleus.org/products/accessplatform_4_0/jpa/jpql_criteria.html#metamodel

The Eclipse instructions are at the bottom of the page.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29