Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] DAO configuration and JSON customization(DAO configuration and JSON customization)
[Texo] DAO configuration and JSON customization [message #1653719] Fri, 06 March 2015 10:56 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

2 questions.

1. How does the EntityManagerProvider know which database to use. Could not find the reference to configuring the underlying database, h2 in my case. I generated DAO classes, maybe should have done JPA as I know about persistence.xml. Not clear how I would attach my dao context.xml file to the EntityManagerProvider. Once the system is initialised and H2 creates an empty database, will the EntityManager automatically create the required schema?

2. The team I am working with have already written the JSON calls in the js client, of course the structure of the JSON does not match the automatically generated JSON structures Texo produces. Wondering if you can alter the JSON structure. Not really a problem as I will just use a separate Jersey supported JSON service and be satisfied with the DAO support Texo provides.

Regards,

David

[Updated on: Fri, 06 March 2015 11:00]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1653793 is a reply to message #1653719] Fri, 06 March 2015 11:38 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
See replies inline.

gr. Martin

On 06-03-15 11:56, David Wynter wrote:
> Hi,
>
> 2 questions.
> 1. How does the EntityManagerProvider know which database to use. Could not find the reference to configuring the
> underlying database, h2 in my case. I generated DAO classes, maybe should have done JPA as I know about persistence.xml.
> Not clear how I would attach my dao context.xml file to the EntityManagerProvider.
MT>> There should be a persistence.xml which does this. The DAO classes uses JPA/EntityManager calls to persist data.

>
> 2. The team I am working with have already written the JSON calls in the js client, of course the structure of the JSON
> does not match the automatically generated JSON structures Texo produces. Wondering if you can alter the JSON structure.
> Not really problem as I will just use a separate Jersey supported JSON service and be satisfied with the DAO support
> Texo provides.
MT>> Texo has a simple/effective component concept:
https://wiki.eclipse.org/Texo/Components

In this case you can extend the JSONServiceContext (which is also a component) with your own subclass, override the
setRequestContent method for example to convert your json-string to something Texo expects.
There are also several points/components you can replace to convert what Texo expects.

One thing what Texo does with JSON is that it resolves object references to data from the database or new objects (if
needed). That's something you can make use of maybe.

btw, if you don't use the Texo JSONRestWebServiceServlet you can also directly use the Texo model operations with your
custom service context. There are these modeloperations:
RetrieveModelOperation
UpdateInsertModelOperation
DeleteModelOperation

The flow is something like this:
final UpdateInsertModelOperation operation = ComponentProvider.getInstance().newInstance(
UpdateInsertModelOperation.class);
operation.setServiceContext(serviceContext);
operation.execute();

then after this call the serviceContext.getResponseContext() will contain the resulting json.

In any case, if your json format is something standard then you can also let me know if it makes sense to support it in
Texo itself.

gr. Martin


> Regards,
>
> David
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1690686 is a reply to message #1653793] Mon, 30 March 2015 15:37 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Just the connection to DAO is my outstanding issue

I am trying to test some of my DAO code using JUnit. In the setup() method I have this

        final PssErrorTypeDao errTypeDao = DaoRegistry.getInstance().getDao(PssErrorTypeDao.class);


It returns null.

I had moved a copy of my META-INF/persistance.xml to the src/main directory as it is on the classpath.

In it I have

...
	<persistence-unit name="pss_h2" transaction-type="RESOURCE_LOCAL">
		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		<class>org.example.pss.PssErrorType</class>	
		<properties>
            <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:file://~/git/pss/db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"/>
         	<property name="javax.persistence.jdbc.user" value="sa"/>
            <property name="javax.persistence.jdbc.password" value="@@@"/>

			<!-- EclipseLink should create the database schema automatically -->
			<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
			<property name="eclipselink.ddl-generation.output-mode" value="database" />
		</properties>
	</persistence-unit>
</persistence>


Is there anything else I need for the DaoRegistry to be properly initialised?


[Updated on: Mon, 30 March 2015 15:40]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1690731 is a reply to message #1690686] Mon, 30 March 2015 21:31 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
In the generated ModelPackage initialize method there should be a line like this:
DaoRegistry.getInstance().registerDao(ActionType.class, ActionTypeDao.class);

If it is there then I guess you need to touch the model package before you try the code before, for example by calling
initialize on the model package.

Let me know if it works then I will change the wiki.

gr. Martin

On 30-03-15 17:37, David Wynter wrote:
> Hi,
>
> Just the connection to DAO is my outstanding issue
>
> I am trying to test some of my DAO code using JUnit. In the setup() method I have this
>
> final PssErrorTypeDao errTypeDao = DaoRegistry.getInstance().getDao(PssErrorTypeDao.class);
>
>
> It returns null.
>
> I had moved a copy of my META-INF/persistance.xml to the src/main directory as it is on the classpath.
>
> In it I have
>
> ...
> <persistence-unit name="pss_h2" transaction-type="RESOURCE_LOCAL">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
> <class>com.rmg.parcels.pss.PssErrorType</class>
> <properties>
> <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
> <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
> <property name="javax.persistence.jdbc.url"
> value="jdbc:h2:file://~/git/pss/db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"/>
> <property name="javax.persistence.jdbc.user" value="sa"/>
> <property name="javax.persistence.jdbc.password" value="@@@"/>
>
> <!-- EclipseLink should create the database schema automatically -->
> <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
> <property name="eclipselink.ddl-generation.output-mode" value="database" />
> </properties>
> </persistence-unit>
> </persistence>
>
>
> Is there anything else I need for the DaoRegistry to be properly initialised?
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1690861 is a reply to message #1690731] Tue, 31 March 2015 16:02 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Martin,

The initialize method worked. But not sure how Texo resolves the persistence.xml file? The JUnit test I run from Eclipse, where I ended up explicitly adding to the resource classpath runtime of the JUnit runner the directory where the copy of the persistence.xml is and still it fails to load it, see the code below, it prints out null

	public void setUp() throws Exception {
		// Insert the errortypes
        String err = PssErrorTypes.getErrorTypes();
        ParcelSystemSimulationModelPackage.initialize();
        System.out.println(getClass().getResource("META-INF/persistence.xml"));

The file is under src/test/resources/META-INF/persistence.xml Both src/test and explicitly src/test/resource are on the class path according to the eclipse debug configuration for this Junit test. I realise probably a Eclipse issue. Will setup a test section in the pom.xml next to see if I can get it to run from there.

thx

David

[Updated on: Tue, 31 March 2015 16:03]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1690915 is a reply to message #1690861] Tue, 31 March 2015 21:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
The ORM does the resolving/finding of the persistence.xml, in my case I have META-INF directly within src. Maybe it goes
wrong with you because src/test/resources is a subdirectory src/test which is also on the classpath.So maybe moving
META-INF one level up solves it.

gr. Martin

On 31-03-15 18:02, David Wynter wrote:
> Martin,
>
> The initialize method worked. But not sure how Texo resolves the persitance.xml file? My JUnit test I run from Eclipse,
> where I ended up explicitly adding to the resurce classpath runtime of the JUnit runner the directory where the copy of
> the persistence.xml is and still it fails to load it, see the code below, it prints out null
>
>
> public void setUp() throws Exception {
> // Insert the errortypes
> String err = PssErrorTypes.getErrorTypes();
> ParcelSystemSimulationModelPackage.initialize();
> System.out.println(getClass().getResource("META-INF/persistence.xml"));
>
> The file is under src/test/resources/META-INF/persistence.xml Both src/test and explicitly src/test/resource are on the
> class path according to the eclipse debug configuration for this Junit test. I realise probably a Eclipse issue. Will
> setup a test section in the pom.xml next to see if I can get it to run from there.
>
> thx
>
> David


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1691090 is a reply to message #1690915] Thu, 02 April 2015 09:35 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

It turned out to be some Windows thing, it changed my file permissions to admin for the target class path, so it could not output the new version of the classes?! Anyway sorted that out. Followed your advice an moved the META-INf/persistance to my src-gen top package. Now it does print out the resource in console, see code above. But despite persistence.xml now being on the classpath I still get

javax.persistence.PersistenceException: No Persistence provider for EntityManager named pss_h2
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
	at com.example.parcels.pss.resources.ReferenceResourceTests.setUp(ReferenceResourceTests.java:49)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)


So tried this

        Map<String, String> properties = new HashMap<String, String>();
        properties.put("eclipselink.target-database", "org.eclipse.persistence.platform.database.H2Platform");
        properties.put("javax.persistence.jdbc.driver", "org.h2.Driver");
        properties.put("eclipselink.ddl-generation", "drop-and-create-tables");
        properties.put("eclipselink.ddl-generation.output-mode", "database");
        properties.put("javax.persistence.jdbc.user", "sa");
        properties.put("javax.persistence.jdbc.url", "jdbc:h2:file://C:/Users/myuser/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE");
        properties.put("javax.persistence.jdbc.password", "pss@1234");
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            "pss_h2", properties);

Same result. How do I get deeper trace detail to find out why it does not use the valid persistence.xml to create the required EntityManagerFactory instance?

[Updated on: Thu, 02 April 2015 10:00]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691091 is a reply to message #1690915] Thu, 02 April 2015 09:38 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

It turned out to be some Windows thing, it changed my file permissions to admin for the target class path?! Anyway sorted that out. Followed your advice an moved the META-INF/persistance to my src-gen top package.

I use the std EntityManagerFactory code prior to the DaoRegistry code to prove the persistence.xml is being picked up. Although it appears not completely?

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pssh2");
        EntityManager em = emf.createEntityManager();

        final PssErrorTypeDao errTypeDao = DaoRegistry.getInstance().getDao(PssErrorTypeDao.class);


persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
	xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="pssh2" transaction-type="RESOURCE_LOCAL">
		<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
		<class>com.example.parcels.pss.AdvancedConfig</class>	
		<class>com.example.parcels.pss.AdvancedConfigPreAdviceQuality</class>	
		<class>com.example.parcels.pss.BasicConfig</class>	
		<class>com.example.parcels.pss.ChannelMeta</class>	
		<class>com.example.parcels.pss.CustomerMeta</class>	
		<class>com.example.parcels.pss.ErrorType</class>	
		<class>com.example.parcels.pss.PssErrorType</class>	
		<class>com.example.parcels.pss.MetaConfig</class>	
		<class>com.example.parcels.pss.MPEMeta</class>	
		<class>com.example.parcels.pss.SenderMeta</class>	
		<class>com.example.parcels.pss.TrailerMeta</class>	
		<class>com.example.parcels.pss.PreAdviceHdrMeta</class>	
		<class>com.example.parcels.pss.Rule</class>	
		<class>com.example.parcels.pss.ScheduleRun</class>	
		<properties>
            <property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:file://C:/Users/david.user/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"/>
         	<property name="javax.persistence.jdbc.user" value="sa"/>
            <property name="javax.persistence.jdbc.password" value="******"/>

			<!-- EclipseLink should create the database schema automatically -->
			<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
			<property name="eclipselink.ddl-generation.output-mode" value="both" />
		</properties>
	</persistence-unit>
</persistence>


This is the output from the EntityManager, it does not show the 12 <class></class> entries I have in my persistence.xml

[EL Info]: 2015-04-02 11:37:07.785--ServerSession(1754570454)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Info]: 2015-04-02 11:37:12.714--ServerSession(1754570454)--file:/C:/Users/david.wynter/git/pss/target/classes/_pssh2 login successful
[EL Warning]: 2015-04-02 11:37:12.78--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units.  Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element


Finally I get this trace form the DaoRegistry call

javax.persistence.PersistenceException: No Persistence provider for EntityManager named null
	at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
	at org.eclipse.emf.texo.server.store.EntityManagerProvider.initialize(EntityManagerProvider.java:73)
	at org.eclipse.emf.texo.server.store.EntityManagerProvider.createEntityManager(EntityManagerProvider.java:86)
	at org.eclipse.emf.texo.server.store.EntityManagerProvider.getEntityManager(EntityManagerProvider.java:99)
	at org.eclipse.emf.texo.server.store.BaseDao.getEntityManager(BaseDao.java:77)
...


any ideas?

[Updated on: Thu, 02 April 2015 10:53]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691099 is a reply to message #1691091] Thu, 02 April 2015 10:18 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Can also be caused by that eclipselink is not found, can you check that indeed the eclipselink jar is on the classpath?
And for completeness can you post the persistence.xml? This is running junit? (or junit plugin test)

gr. Martin

On 02-04-15 11:38, David Wynter wrote:
> Hi,
>
> It turned out to be some Windows thing, it changed my file permissions to admin for the target class path?! Anyway
> sorted that out. Followed your advice an moved the META-INf/persistance to my src-gen top package. Now it does print
> out the resource in console, using
>
> System.out.println(getClass().getResource("META-INF/persistence.xml"));
>
> But despite persistence.xml now being on the classpath I still get
>
> javax.persistence.PersistenceException: No Persistence provider for EntityManager named pss_h2
> at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
> at com.rmg.parcels.pss.resources.ReferenceResourceTests.setUp(ReferenceResourceTests.java:49)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
>
>
> So tried this
>
> Map<String, String> properties = new HashMap<String, String>();
> properties.put("eclipselink.target-database", "org.eclipse.persistence.platform.database.H2Platform");
> properties.put("javax.persistence.jdbc.driver", "org.h2.Driver");
> properties.put("eclipselink.ddl-generation", "drop-and-create-tables");
> properties.put("eclipselink.ddl-generation.output-mode", "database");
> properties.put("javax.persistence.jdbc.user", "sa");
> properties.put("javax.persistence.jdbc.url",
> "jdbc:h2:file://C:/Users/myuser/git/pss/db/pss_db;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE");
> properties.put("javax.persistence.jdbc.password", "pss@1234");
> EntityManagerFactory emf = Persistence.createEntityManagerFactory(
> "pss_h2", properties);
>
> Same result. How do I get deeper trace detail to find out why it doe snot use the valid persistence.xml to create the
> required EntityManagerFactory instance?
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1691107 is a reply to message #1691099] Thu, 02 April 2015 11:05 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I checked the Eclipse Debug Configuration for the JUnit test I am running. It shows that my project is included, and it include all the jars you specified, including eclipselink.jar and the required h2 jar in WebContent/WEB-INF/lib. It also includes the javax.persistence jar, which is being picked up by the code I edited in the earlier post I did above. I.e. std EntityManagerFactory appears to find that jar which is in the same directory. Also, wouldn't something throw an exception is eclipselink.jar was not on the classpath?

Thx.

David

[Updated on: Thu, 02 April 2015 11:30]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691113 is a reply to message #1691107] Thu, 02 April 2015 11:38 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
The exception you mention can happen when there is no ORM on the classpath and no I don't think you would get an earlier
exception as you can do ORM things before getting the entitymanagerfactory.

can you send me the persistence.xml? Just to see what's in there.

gr. Martin

On 02-04-15 13:05, David Wynter wrote:
> Hi,
>
> I checked the Eclipse Debug Configuration for the JUnit test I am running. It shows that my project is included, and it
> include all the jars you specified, including eclipselink.jar and the required h2 jar in WebContent/WEB-INF/lib. It also
> includes the javax.persitence jar, which is being picked up by the code I edited in the earlier post I did above. I.e.
> std EntityManagerFactory appears to find that jar which is in the same directory. Also, wouldn't something throw an
> exception is eclipselink.jar wa snot on the classpath?
>
> Thx.
>
> David


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1691114 is a reply to message #1691107] Thu, 02 April 2015 12:00 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
OK, this is interesting, clearly a problem with my persistence.xml.

I included this
		<exclude-unlisted-classes>false</exclude-unlisted-classes>

And it gave me this error

Exception Description: Predeployment of PersistenceUnit [pssh2] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class com.example.parcels.pss.actors.CreatePreAdvice] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.


Which is expected, because I don't want all of my generated classes to be persisted, which is why I explicitly use the <class></class> properties.

So the question is that my perisistence.xml is wrong in some way, but the code does not throw an exception due to that particular error, because it does for other errors as shown above.
Re: [Texo] DAO configuration and JSON customization [message #1691154 is a reply to message #1691114] Thu, 02 April 2015 15:11 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Trying to understand the relationship between the EntityManagerProvider and DaoRegistry.

You can see here I explicitly set the EntityManager in the EntityManagerProvider.
But when the DaoRegistry instance returns the PssErrorTypeDao the field that holds the EntityManager is null? So they appear unconnected.
Not sure what other steps are required to make sure the Dao objects returned are initialised. I note that the entityName field is null too?

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pssh2");
        EntityManager em = emf.createEntityManager();
        EntityManagerProvider.getInstance().setEntityManagerFactory(emf);
        EntityManagerProvider.getInstance().setCurrentEntityManager(em);
        
        final PssErrorTypeDao errTypeDao = DaoRegistry.getInstance().getDao(PssErrorTypeDao.class);


It appears despite having these 2 fields null it works, but is still not recognising all the <class> entries in the persistence.xml, because I get this:

[code]
java.lang.IllegalArgumentException: Object: PssErrorType [code: GAN] [description: Check the value in 'Header' field: 'Generic Account Number' is valid (Applicable for DOSS, DMO and Shipping API channels)] [fieldApplied: Generic Account Number] is not a known entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4158)
[/code]

Maybe I have misread, is a annotations model mandatory? It does not seem so from this page: - http://wiki.eclipse.org/Texo/Code_Generation_Details

[Updated on: Thu, 02 April 2015 15:44]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691157 is a reply to message #1691154] Thu, 02 April 2015 15:50 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Also call the setUseCurrentEntityManagerPattern on the entity manager provider... This feature is used in Texo testing
so therefore misses this last fine print doc that you need to call this method. I will add it to the javadoc at least.

The entityName in the DAO is computed when you call getEntityName not before (as it needs the entitymanager).

The EntityManagerFactory gets created correctly? If not can you post the persistence.xml?

gr. Martin

On 02-04-15 17:11, David Wynter wrote:
> Trying to understand the relationship between the EntityManagerProvider and DaoRegistry.
>
> You can see here I explicitly set the EntityManager in the EntityManagerProvider.
> But when the DaoRegistry instance returns the PssErrorTypeDao the field that holds the EntityManager is null? So they
> appear unconnected.
> Not sure what other steps are required to make sure the Dao objects returned are initialised. I note that the entityName
> field is null too?
>
>
> EntityManagerFactory emf = Persistence.createEntityManagerFactory("pssh2");
> EntityManager em = emf.createEntityManager();
> EntityManagerProvider.getInstance().setEntityManagerFactory(emf);
> EntityManagerProvider.getInstance().setCurrentEntityManager(em);
> final PssErrorTypeDao errTypeDao = DaoRegistry.getInstance().getDao(PssErrorTypeDao.class);
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1691428 is a reply to message #1691157] Tue, 07 April 2015 08:40 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I added the call but still get the exception. The persistence.xml is the one you see in an earlier message, message #1691091. I inspect the field values in the debugger for both EntityManagerFactory and EntityManager and can see the list of classes defined in the persistence.xml, under em/factory/setupImpl/persistenceUnitInfo/managedClassNames/elementData. I also checked it's structure against the Oracle reference for persistence.xml and it looks ok, maybe I am missing something?

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pssh2");
        EntityManager em = emf.createEntityManager();
        EntityManagerProvider.getInstance().setEntityManagerFactory(emf);
        EntityManagerProvider.getInstance().setCurrentEntityManager(em);
        EntityManagerProvider.getInstance().setUseCurrentEntityManagerPattern(true); 
        
        final PssErrorTypeDao errTypeDao = DaoRegistry.getInstance().getDao(PssErrorTypeDao.class);
...


Exception

[code]
java.lang.IllegalArgumentException: Object: PssErrorType [code: GAN] [description: Check the value in 'Header' field: 'Generic Account Number' is valid (Applicable for COSS, DMO and Shipping API channels)] [fieldApplied: Generic Account Number] is not a known entity type.
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4158)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:440)
at org.eclipse.emf.texo.server.store.BaseDao.insert(BaseDao.java:204)
at com.example.parcels.pss.resources.ReferenceResourceTests.setUp(ReferenceResourceTests.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
...
[/code]

I'll continue to try to alter persistence.xml to see if I can get the em of emf to pick up the classes defined. If not then create a separate mapping file .

[Updated on: Tue, 07 April 2015 09:46]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691471 is a reply to message #1691428] Tue, 07 April 2015 13:27 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
I tried to use the EntityManager.persist method and it fails with the same exception. So something about the EntityManager is not formed correctly. While it has the persistent classes defined in it's structure something else internally causes it to fail. Could this be due to me running this from a JUnit test? I do add the entire project to the classpath so the classes should be visible to EntityManager, the fact it reads the persistence.xml which is in the same directory structure suggests it can read that path.

I note that the console log shows this :
[EL Warning]: 2015-04-07 14:25:16.286--The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units. Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element

So even though the classes are listed in the EntityManager instance structure it appears it cannot find them? I am assuming that in addition to the place I found them listed they should also be listed here too for it to work:
MetamodelImpl@1710971789 [ 0 Types: , 0 ManagedTypes: , 0 EntityTypes: , 0 MappedSuperclassTypes: , 0 EmbeddableTypes: ]

[Updated on: Tue, 07 April 2015 13:34]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691489 is a reply to message #1691471] Tue, 07 April 2015 15:11 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
I got it to work by making sure I generated JPA with DAO and then going through and all classes in the ecore that have a field where ID == true I changed the generated code from using a @Basic() annotation on that field to a @Id() annotation.

[Updated on: Tue, 07 April 2015 15:48]

Report message to a moderator

Re: [Texo] DAO configuration and JSON customization [message #1691520 is a reply to message #1691489] Tue, 07 April 2015 19:06 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Hmm, these annotations should be generated automatically when you choose generate JPA annotated model code. Did you do
that (I assumed this..) or choose another generation method?

gr. Martin

On 07-04-15 17:11, David Wynter wrote:
> Got std JPA ith DAO to work by adding the @Entity and @Id annotations to the domain classes generated by Texo. Will have
> to forego extra Texo features, at least I can persist now.


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] DAO configuration and JSON customization [message #1691620 is a reply to message #1691520] Wed, 08 April 2015 13:58 Go to previous message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I must have l clicked on the "Generate Model + Dao code" menu at some point. When I realised this I then clicked the "Generate JPA Annotated Model + Dao" menu it generated the annotations.

The only issue I had was even though all my persisted classes have a field with Unique=true and ID=true the annotation generated for these was @Basic and not @Id, so I changed them manually and where appropriate (EInt) added @GeneratedValue with args.

Thx.

David
Previous Topic:[EEF] Update to tutorial
Next Topic:[Teneo] How can I persist java.util.Calendar as "timestamp with timezone"?
Goto Forum:
  


Current Time: Thu Mar 28 15:37:46 GMT 2024

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

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

Back to the top