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 05:56  |
Eclipse User |
|
|
|
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 06:00] by Moderator
|
|
|
Re: [Texo] DAO configuration and JSON customization [message #1653793 is a reply to message #1653719] |
Fri, 06 March 2015 06:38   |
Eclipse User |
|
|
|
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 #1690915 is a reply to message #1690861] |
Tue, 31 March 2015 17:25   |
Eclipse User |
|
|
|
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 05:35   |
Eclipse User |
|
|
|
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 06:00] by Moderator
|
|
| |
Re: [Texo] DAO configuration and JSON customization [message #1691099 is a reply to message #1691091] |
Thu, 02 April 2015 06:18   |
Eclipse User |
|
|
|
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 #1691113 is a reply to message #1691107] |
Thu, 02 April 2015 07:38   |
Eclipse User |
|
|
|
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 #1691620 is a reply to message #1691520] |
Wed, 08 April 2015 09:58  |
Eclipse User |
|
|
|
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
|
|
|
Goto Forum:
Current Time: Wed Jul 23 14:22:08 EDT 2025
Powered by FUDForum. Page generated in 0.07691 seconds
|