Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [ Acceleo 3] java service get a empty Jpa metamodel([ Acceleo 3] java service get a empty Jpa metamodel)
[ Acceleo 3] java service get a empty Jpa metamodel [message #655319] Sat, 19 February 2011 12:23 Go to next message
Philippe Palau is currently offline Philippe PalauFriend
Messages: 13
Registered: February 2011
Junior Member
hi,
i use accelo 3 for generate java from Uml. i try reuse some part of my custom generator based on the jpa metamodel.
I' added all dependents jar in the classpath runtime :
- javax.persistence,
- eclipseLink
- my Entities and the generated jpa metamodel with the ressource-local persistence.xml

I' try to get the jpa metamodel in a java service.
I' don't get any class not found error, i obtains the jpa metamodel for my PersistenceUnit but it is empty:
MetamodelImpl@335173235 [ 0 Types: , 0 ManagedTypes: , 0 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes:]

Using same jars in a simple java project i' obtain the jpa metamodel fully loaded
MetamodelImpl@1779280140 [ 30 Types: , 25 ManagedTypes: , 24 EntityTypes: , 1 MappedSuperclassTypes: , 0 EmbeddableTypes: ]

Does anyone know what is wrong or has any idea ?

Thanks.

Re: [ Acceleo 3] java service get a empty Jpa metamodel [message #655480 is a reply to message #655319] Mon, 21 February 2011 10:08 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060206020704070606010500
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Philippe,

We'll need more information about what you're doing if we are to help you.

What exactly do you mean by "get the jpa metamodel"? Could you post the
relevant java code?

What is the difference between your two approches ?

Laurent Goubet
Obeo

On 19/02/2011 13:23, Philippe Palau wrote:
> hi,
> i use accelo 3 for generate java from Uml. i try reuse some part of my
> custom generator based on the jpa metamodel.
> I' added all dependents jar in the classpath runtime : - javax.persistence,
> - eclipseLink
> - my Entities and the generated jpa metamodel with the ressource-local
> persistence.xml
>
> I' try to get the jpa metamodel in a java service. I' don't get any
> class not found error, i obtains the jpa metamodel for my
> PersistenceUnit but it is empty:
> mailto:MetamodelImpl@335173235 [ 0 Types: , 0 ManagedTypes: , 0
> EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes:]
>
> Using same jars in a simple java project i' obtain the jpa metamodel
> fully loaded
> mailto:MetamodelImpl@1779280140 [ 30 Types: , 25 ManagedTypes: , 24
> EntityTypes: , 1 MappedSuperclassTypes: , 0 EmbeddableTypes: ]
> Does anyone know what is wrong or has any idea ?
> Thanks.
>
>


--------------060206020704070606010500
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------060206020704070606010500--
Re: [ Acceleo 3] java service get a empty Jpa metamodel [message #655487 is a reply to message #655480] Mon, 21 February 2011 11:57 Go to previous messageGo to next message
Philippe Palau is currently offline Philippe PalauFriend
Messages: 13
Registered: February 2011
Junior Member
Hi Laurent,

by get the jpa metamodel i' mean using regular JPA code for obtain an EntiyManager and get the jpa metamodel from it.

        // for test: get the jpa model and return its string representation
       // 'sgp' is the persistence unit name
	public String generateDaoQueryMethods(org.eclipse.uml2.uml.Class cl) {		
		try {			
			String out = "";
			Metamodel metamodel = null;
			EntityManager em = EntityManagerProvider.createEM("sgp", new HashMap());
			metamodel = em.getMetamodel();
			out += "//" + metamodel.toString();
			return out;
                       //return generateQueries(cl, EMIT_TYPE.DAO);
		} catch (Exception e) {
			return AcceleoGeneratorHelper.dumpStackTrace(e);
		}
		//return generateQuery(testQueryDefinition(), EMIT_TYPE.DAO);
	}

       public static void main(String[] args) {
		System.out.println(new QueryGeneratorService().generateDaoQueryMethods(null));
	}





EntityManagerProvider utility class (only JPA statements)
public class EntityManagerProvider {

	private static Map<String, EntityManagerFactory> emfPUs = new HashMap<String, EntityManagerFactory>();

	public static EntityManagerFactory getEMFactory(String pUName, Map properties) {
		EntityManagerFactory emfPU = emfPUs.get(pUName);
		if (emfPU == null) {
			emfPU = Persistence.createEntityManagerFactory(pUName, properties);
			emfPUs.put(pUName, emfPU);
		}
		return emfPU;
	}

	public static EntityManager createEM(String pUName, Map properties) {
		return getEMFactory(pUName, properties).createEntityManager(properties);
	}
	public static EntityManager createEM(String pUName) {
		return createEM(pUName, new HashMap());
	}
			
}
]


the two approach:

In first approach generateDaoQueryMethods is called through a java wrapped service by a query used in a template. (running acceleo as 'Acceleo Plug-in Application')
the emitted output in file is :
//MetamodelImpl@335173235 [ 0 Types: , 0 ManagedTypes: , 0 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes:]

All required jars are referenced in the Runtime Classpath and none exception occurs but the jpaMetamodel contains 0 managed types. That's the problem.

In second approach generateDaoQueryMethods is called by a simple java main
using the same acceleo project java build path (same jars)

the console output is :
//MetamodelImpl@1085278557 [ 30 Types: , 25 ManagedTypes: , 24 EntityTypes: , 1 MappedSuperclassTypes: , 0 EmbeddableTypes: ]

in brief: i' try to understand why the behavior is different when code is run as acceleo pluggin .

I' hope my description will be useful

Many thanks,
Philippe
Re: [ Acceleo 3] java service get a empty Jpa metamodel [message #655506 is a reply to message #655487] Mon, 21 February 2011 13:15 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060404050904030406070601
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Philippe,

I must admit that I don't know the JPA enough to really be of any help
here. The persistance problem seem to come from the pluginization of
your project ... but why, I don't really know.

You could try using plugin dependencies instead of additions to the
class path (through the META-INF/MANIFEST.MF dependencies tab). Other
than that, I can only suggest you to debug the execution of your code in
order to see why the loaded model is empty.

Laurent Goubet
Obeo

On 21/02/2011 12:57, Philippe Palau wrote:
> Hi Laurent,
>
> by get the jpa metamodel i' mean using regular JPA code for obtain an
> EntiyManager and get the jpa metamodel from it.
>
>
> // for test: get the jpa model and return its string representation
> // 'sgp' is the persistence unit name
> public String generateDaoQueryMethods(org.eclipse.uml2.uml.Class cl) {
> try {
> String out = "";
> Metamodel metamodel = null;
> EntityManager em = EntityManagerProvider.createEM("sgp", new HashMap());
> metamodel = em.getMetamodel();
> out += "//" + metamodel.toString();
> return out;
> //return generateQueries(cl, EMIT_TYPE.DAO);
> } catch (Exception e) {
> return AcceleoGeneratorHelper.dumpStackTrace(e);
> }
> //return generateQuery(testQueryDefinition(), EMIT_TYPE.DAO);
> }
>
> public static void main(String[] args) {
> System.out.println(new
> QueryGeneratorService().generateDaoQueryMethods(null));
> }
>
>
>
>
>
> EntityManagerProvider utility class (only JPA statements)
>
> public class EntityManagerProvider {
>
> private static Map<String, EntityManagerFactory> emfPUs = new
> HashMap<String, EntityManagerFactory>();
>
> public static EntityManagerFactory getEMFactory(String pUName, Map
> properties) {
> EntityManagerFactory emfPU = emfPUs.get(pUName);
> if (emfPU == null) {
> emfPU = Persistence.createEntityManagerFactory(pUName, properties);
> emfPUs.put(pUName, emfPU);
> }
> return emfPU;
> }
>
> public static EntityManager createEM(String pUName, Map properties) {
> return getEMFactory(pUName, properties).createEntityManager(properties);
> }
> public static EntityManager createEM(String pUName) {
> return createEM(pUName, new HashMap());
> }
>
> }
> ]
>
> the two approach:
>
> In first approach generateDaoQueryMethods is called through a java
> wrapped service by a query used in a template. (running acceleo as
> 'Acceleo Plug-in Application')
> the emitted output in file is :
> //mailto:MetamodelImpl@335173235 [ 0 Types: , 0 ManagedTypes: , 0
> EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes:]
>
> All required jars are referenced in the Runtime Classpath and none
> exception occurs but the jpaMetamodel contains 0 managed types. That's
> the problem.
>
> In second approach generateDaoQueryMethods is called by a simple java main
> using the same acceleo project java build path (same jars)
>
> the console output is :
> //mailto:MetamodelImpl@1085278557 [ 30 Types: , 25 ManagedTypes: , 24
> EntityTypes: , 1 MappedSuperclassTypes: , 0 EmbeddableTypes: ]
>
> in brief: i' try to understand why the behavior is different when code
> is run as acceleo pluggin .
>
> I' hope my description will be useful
>
> Many thanks,
> Philippe
>


--------------060404050904030406070601
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------060404050904030406070601--
Re: [ Acceleo 3] java service get a empty Jpa metamodel [message #655539 is a reply to message #655506] Mon, 21 February 2011 16:28 Go to previous messageGo to next message
Philippe Palau is currently offline Philippe PalauFriend
Messages: 13
Registered: February 2011
Junior Member
Hi Laurent,

I think it's a JPA problem when it trys to acces Entities classes.
Does the acceleo pluggin runtime environment has some particularities that i have to know ?
I'll test your proposal and try to understand or find a workaround and give you feedback on this thread.

Many thanks
Philippe
Re: [ Acceleo 3] java service get a empty Jpa metamodel [message #657532 is a reply to message #655539] Thu, 03 March 2011 08:28 Go to previous message
Philippe Palau is currently offline Philippe PalauFriend
Messages: 13
Registered: February 2011
Junior Member
Hi,

After trying many ways I did not found solution.
I launch my custom tools through a RMI service.
Best regards.
Previous Topic:Crash Eclipse Acceleo
Next Topic:[Acceleo] eliminate white lines generated by template
Goto Forum:
  


Current Time: Sat Dec 20 05:59:39 GMT 2014

Powered by FUDForum. Page generated in 0.02552 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software