Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Java JPA in MATLAB 2007b

Subject: Java JPA in MATLAB 2007b

From: John reilly

Date: 7 Dec, 2010 12:30:07

Message: 1 of 3

I'm using MATLAB R2007b, Java 1.6 SE, Eclipse Helios, and MySql 5 on Windows XP Pro SP3.

I'm trying to create a class library that uses JPA annotations to access a MySql 5 database. The idea is that the MATLAB script instantiates these Java objects, which provide an API for accessing the DB.

I can create my annotated classes, which work within Eclipse (i.e. JUnit test). I can export the code to a jar, which I can run from a command prompt, and that works.

I update the MATLAB Java classpath using javaaddpath(). I can instantiate my class within MATLAB. But when I call my init(), which calls javax.persistence.Persistence.createEntityManagerFactory(), I get the dreaded

"No Persistence provider for EntityManager"

This error usually means that the persistence.xml file isn't in the right place. But it must be because my jar works from the command line. Adding the META-INF folder to the MATLAB java classpath doesn't help. Nor does extracting the jar and adding the extracted folder structure to the classpath, whether or not META-INF is added.

Does anyone have any ideas, nutty or not? Has anyone ever done this in any version of MATLAB.

Thanks.

-reilly.

Subject: Java JPA in MATLAB 2007b

From: Yair Altman

Date: 7 Dec, 2010 20:28:06

Message: 2 of 3

"John Reilly" <jrhokie1.nospam@yahoo.com> wrote in message <idl9cf$i1m$1@fred.mathworks.com>...
> I'm using MATLAB R2007b, Java 1.6 SE, Eclipse Helios, and MySql 5 on Windows XP Pro SP3.
>
> I'm trying to create a class library that uses JPA annotations to access a MySql 5 database. The idea is that the MATLAB script instantiates these Java objects, which provide an API for accessing the DB.
>
> I can create my annotated classes, which work within Eclipse (i.e. JUnit test). I can export the code to a jar, which I can run from a command prompt, and that works.
>
> I update the MATLAB Java classpath using javaaddpath(). I can instantiate my class within MATLAB. But when I call my init(), which calls javax.persistence.Persistence.createEntityManagerFactory(), I get the dreaded
>
> "No Persistence provider for EntityManager"
>
> This error usually means that the persistence.xml file isn't in the right place. But it must be because my jar works from the command line. Adding the META-INF folder to the MATLAB java classpath doesn't help. Nor does extracting the jar and adding the extracted folder structure to the classpath, whether or not META-INF is added.
>
> Does anyone have any ideas, nutty or not? Has anyone ever done this in any version of MATLAB.
>
> Thanks.
>
> -reilly.


Try placing your JAR file in Matlab's static classpath (type "edit('classpath.txt')" at the Matlab Command prompt), then restart Matlab and retry (no need for javaaddpath any more).

There should be no difference between using the dynamic and static Java classpath in Matlab, but in practice using the static classpath solves many issues - this could possibly be one of them. Let us know what happens.

Yair Altman
http://Undocumentedmatlab.com

Subject: Java JPA in MATLAB 2007b

From: John reilly

Date: 8 Dec, 2010 11:10:07

Message: 3 of 3

Thanks, Yair. That did the trick.

I first upgraded to R2010a because the JVM is much newer. (I tried changing R2007b to use 1.6 and ML wouldn't even start!) Setting the dynamic path failed with the same error as R2007b.

Then I added my jars to the END of the static classpath. I got different errors that led me to believe it was a jar version issue.

So I added my jars to the BEGINNING of the static classpath. This worked. Everything is 5-by-5.

I don't quite get the why, and I'm not sure how I'll deploy, but the code now works.

Thanks again.

-John.

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <idm5cm$8sh$1@fred.mathworks.com>...
> "John Reilly" <jrhokie1.nospam@yahoo.com> wrote in message <idl9cf$i1m$1@fred.mathworks.com>...
> > I'm using MATLAB R2007b, Java 1.6 SE, Eclipse Helios, and MySql 5 on Windows XP Pro SP3.
> >
> > I'm trying to create a class library that uses JPA annotations to access a MySql 5 database. The idea is that the MATLAB script instantiates these Java objects, which provide an API for accessing the DB.
> >
> > I can create my annotated classes, which work within Eclipse (i.e. JUnit test). I can export the code to a jar, which I can run from a command prompt, and that works.
> >
> > I update the MATLAB Java classpath using javaaddpath(). I can instantiate my class within MATLAB. But when I call my init(), which calls javax.persistence.Persistence.createEntityManagerFactory(), I get the dreaded
> >
> > "No Persistence provider for EntityManager"
> >
> > This error usually means that the persistence.xml file isn't in the right place. But it must be because my jar works from the command line. Adding the META-INF folder to the MATLAB java classpath doesn't help. Nor does extracting the jar and adding the extracted folder structure to the classpath, whether or not META-INF is added.
> >
> > Does anyone have any ideas, nutty or not? Has anyone ever done this in any version of MATLAB.
> >
> > Thanks.
> >
> > -reilly.
>
>
> Try placing your JAR file in Matlab's static classpath (type "edit('classpath.txt')" at the Matlab Command prompt), then restart Matlab and retry (no need for javaaddpath any more).
>
> There should be no difference between using the dynamic and static Java classpath in Matlab, but in practice using the static classpath solves many issues - this could possibly be one of them. Let us know what happens.
>
> Yair Altman
> http://Undocumentedmatlab.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us