-->
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.  [ 14 posts ] 
Author Message
 Post subject: Metamodel generation in Eclipse
PostPosted: Wed May 26, 2010 4:00 am 
Regular
Regular

Joined: Wed Oct 15, 2003 4:40 pm
Posts: 67
Hi,

I'm using the latest jpamodelgen and jpa2 with a m2eclipse project in Eclipse which I have set up according to the documentation. The strange thing is that I get the source files generated fine under /target/metamodel but they are not compiled even if that folder is added as a source folder and I have all autobuilding on etc. This results in the that Foo_ classes are not resolved in the code. If I change something in the generated file, it is automagically compiled. This could of course be a eclipse/me2eclipse issue but I thought you guys could have some insight.

Thanks in advance,
-Nik


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Tue Aug 31, 2010 1:04 pm 
Newbie

Joined: Sat Jul 17, 2010 10:33 am
Posts: 4
The same problem here. I also posted this on stackoverflow but, again, no responses.
I wonder how all those Eclipse users use that model generator...


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Tue Aug 31, 2010 1:49 pm 
Newbie

Joined: Thu Jan 22, 2009 6:22 pm
Posts: 5
I had real fun getting the metamodel generator, eclipse, and maven to coordinate on this. Here is what you need to do when using m2eclipse:

Add the following to your POM file:

Code:
<build>
      <plugins>
         <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
               <execution>
                  <id>add-source</id>
                  <phase>generate-sources</phase>
                  <goals>
                     <goal>add-source</goal>
                  </goals>
                  <configuration>
                     <sources>
                        <source>src/generated/java</source>
                     </sources>
                  </configuration>
               </execution>
            </executions>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
               <source>1.6</source>
               <target>1.6</target>
               <compilerArguments>
                  <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
               </compilerArguments>
            </configuration>
         </plugin>
      </plugins>
   </build>


Notice that I am generating sources to the directory src/generated/java. You don't want even generated source code to go to target. Only the compiled classes should go to target.

Open the project properties in eclipse. Go to Java Compiler/Annotation Processing

Enable annotation processing and set the generated source directory to src/generated/java.

Under factory path, you will need to reference the metamodel jar and any dependencies.

As far as I can tell, there is no way to get maven to generate this configuration.

Now, right click on the project and select Maven/Update Project Configuration. This should add a new source directory to you your project called generated/java. You should see your metamodel there.

You do not want to use your main/java directory as the target of the metamodel generator as it will delete all of your source files!

Ted Young


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Sat Sep 04, 2010 10:14 am 
Newbie

Joined: Sat Jul 17, 2010 10:33 am
Posts: 4
Now I get the following error:
Quote:
Build errors for (myproject); org.apache.maven.ProjectBuildFailureException: Build for project: ... failed during execution of mojo: org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile

I also tried the other way, suggested here:
http://docs.jboss.org/hibernate/jpamodelgen/1.0/reference/en-US/html_single/#maven-processor-plugin
but I get the same error. Any ideas?
Suprisingly, if I build using "mvn compile" (with either build configuration), there is no error.

Hopefully, I found a workaround which for some reason works only when using maven-annotation plugin. After I got the error, I just right click on project and then click
Maven -> Update Project Configuration.
This is only required after a clean-up of the project, so I can live with it for the time being.

Anyway, thanks for the detailed info.


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Wed Nov 03, 2010 2:46 pm 
Newbie

Joined: Wed Nov 03, 2010 2:36 pm
Posts: 9
Hello,
I'm also using jpamodelgen and JPA2 but I have a problem..
My project contains multiple packages and other classes without annotations i.e. @Entity and when processor tries to process such classes I get exception in eclipse:

Code:
Internal compiler error: java.lang.NoClassDefFoundError: javax/persistence/Entity at org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor.isJPAEntity(JPAMetaModelEntityProcessor.java:188)   PTMUtils.java   /ptm-model/src/main/java/com/ptm/commons   line 0   Java Problem


is there a way to specify package(s) that JPAMetaModelEntityProcessor should use?
Or how to exclude packages?


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Thu Nov 04, 2010 7:04 am 
Newbie

Joined: Wed Nov 03, 2010 2:36 pm
Posts: 9
My bad.
It not JPAMetaModelEntityProcessor fault. persistence-api just wasn't in the classpath. I added library in annotation processoing factory path and vualia.


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Wed Nov 10, 2010 8:19 am 
Newbie

Joined: Wed Nov 10, 2010 7:13 am
Posts: 2
Hi there, I'm trying to use the hibernate metamodel generator with Eclipse (helios).
I've setup the generated source directory location to "src" since I want generated classes be integrated to the svn, I don't want to integrate this process to maven.

I'm actually able to generate metamodel classes as expected, BUT, I can't make them be recognized by eclipse as new to add into the version control. It's like all generated classes are automatically ignored (svn:ignore).
When I look to the "Synchronize" view, I can't see them...

Can somebody tell me what's I'm doing wrong?

Thanks


Last edited by francois on Wed Nov 10, 2010 8:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Wed Nov 10, 2010 8:29 am 
Newbie

Joined: Wed Nov 03, 2010 2:36 pm
Posts: 9
It might be that there is a filter in SVN that ignores that pattern. I'm pretty sure that it's because of underscore. Try checking Team > Ignored resources settings.


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Wed Nov 10, 2010 8:43 am 
Newbie

Joined: Wed Nov 10, 2010 7:13 am
Posts: 2
@Merllinas

I've checked up the Team->Ignored Resources settings, can't see any patterns that could exclude them.
The funny thing is, when I manually create a class with the name and contents (copy and past) as the generated one, I can version it...

Cheers,


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Fri Nov 12, 2010 11:12 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 4:26 am
Posts: 26
Location: Germany, Dortmund
Hi!

I just played around with the generator. Perhaps somebody can give me some answers to my questions.
Where I get the JAR of the generator?
The ZIP or TGZ only contains the source code: http://sourceforge.net/projects/hiberna ... amodelgen/
Here I found a snapshot: http://snapshots.jboss.org/maven2/org/h ... -SNAPSHOT/

Within Eclipse mainly the generation works, but not always. It seems that an open metaclass file Car_ avoids updating it after saving the entity Car.java.
Anybody have similar experience or a fix for it?

_________________
Bye
Kai


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Tue Jan 04, 2011 3:20 am 
Newbie

Joined: Mon May 08, 2006 1:01 pm
Posts: 5
To get the hibernate-jpamodelgen jar through maven, include the following repository in your pom:
https://repository.jboss.org/nexus/cont ... s/releases

Make sure your version is set to 1.1.1.Final

For example:

Code:
<plugin>
             <groupId>org.bsc.maven</groupId>
             <artifactId>maven-processor-plugin</artifactId>
             <version>1.3.7</version>
             <executions>
                 <execution>
                     <id>process</id>
                     <goals>
                         <goal>process</goal>
                     </goals>
                     <phase>process-sources</phase>
                 </execution>
             </executions>
            <dependencies>
                 <dependency>
                     <groupId>org.hibernate</groupId>
                     <artifactId>hibernate-jpamodelgen</artifactId>
                     <version>1.1.1.Final</version>
                     <scope>compile</scope>
                 </dependency>
             </dependencies>            
         </plugin>      



Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Wed Jan 05, 2011 7:01 am 
Newbie

Joined: Wed Jan 05, 2011 6:43 am
Posts: 1
francois wrote:
I'm actually able to generate metamodel classes as expected, BUT, I can't make them be recognized by eclipse as new to add into the version control. It's like all generated classes are automatically ignored (svn:ignore).
When I look to the "Synchronize" view, I can't see them...


They are being marked as Derived (they are being generated). You can view this in the properies dialog of the _.java files. I don't know if you able to configure this somehow but my guess would be no. It does make sense to mark generated java files as such.

I too have the files being generated into my src/main/java directory and after upgrading to 1.1.1.Final 99.9% of my sources using the Entity_.java metamodel classes don't have errors. I was using 1.0.0.Final and it wasn't reporting the generated classes to the Eclipse JDT compiler, hence the classes referencing the metamodel were having unresolved type errors on a project clean.

Now when I do a project clean, I'm stuck with 1 class which has unresolved type errors. It seems there may yet still be a bug in either jpamodelgen or the way the eclipse annotation processing is done...

For now, I'm stuck with making a trivial change in the 1 class with errors to get it to do an incremental build to clear the errors. I'll report back if I able to figure out exactly what's going on.

Anyone out there having similar issues?

--mgbowman


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Fri Feb 04, 2011 4:51 am 
Newbie

Joined: Fri Feb 04, 2011 4:47 am
Posts: 1
I assume that hibernate meta-model entity processor is generating sources in the last processor round. This is not recommended way and leads exactly to the problem that you have. Explanation is here: http://code.google.com/p/acris/wiki/Cod ... all_Rounds

So the my advise is to generate sources in regular processing rounds and final round should be used just for notification that processing is over or something like that.

I did not study the annotation processor into the details but this should be the problem:
if ( roundEnvironment.processingOver() ) {
if ( !context.isPersistenceUnitCompletelyXmlConfigured() ) {
context.logMessage( Diagnostic.Kind.OTHER, "Last processing round." );
--->>> createMetaModelClasses(); <<<--- THIS GENERATE SOURCE FILE in the last processing round and causes the problems
context.logMessage( Diagnostic.Kind.OTHER, "Finished processing" );
}
return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}
}

Hopefully this helps you.


Top
 Profile  
 
 Post subject: Re: Metamodel generation in Eclipse
PostPosted: Tue May 14, 2013 7:15 pm 
Newbie

Joined: Sat Dec 29, 2012 2:38 pm
Posts: 5
tyoung wrote:
I had real fun getting the metamodel generator, eclipse, and maven to coordinate on this. Here is what you need to do when using m2eclipse:

Add the following to your POM file:

[code]
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/generated/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
.
.
.


Notice that I am generating sources to the directory src/generated/java. You don't want even generated source code to go to target. Only the compiled classes should go to target.

Open the project properties in eclipse. Go to Java Compiler/Annotation Processing

Enable annotation processing and set the generated source directory to src/generated/java.

Under factory path, you will need to reference the metamodel jar and any dependencies.

As far as I can tell, there is no way to get maven to generate this configuration.

Now, right click on the project and select Maven/Update Project Configuration. This should add a new source directory to you your project called generated/java. You should see your metamodel there.

You do not want to use your main/java directory as the target of the metamodel generator as it will delete all of your source files!

Ted Young


Ted,

I revisited this and got it to work in my project . Thanks
Mike


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 posts ] 

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.