You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Hugh (JIRA)" <ji...@apache.org> on 2010/10/28 05:31:20 UTC

[jira] Created: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

How do I get OpenJPA to use my custom classloader to load Entity classes?
-------------------------------------------------------------------------

                 Key: OPENJPA-1860
                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
             Project: OpenJPA
          Issue Type: Question
          Components: jpa
    Affects Versions: 2.0.1
         Environment: OpenJPA 2.0.1 Java 1.6-22
            Reporter: Hugh


I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.

Is this the right approach?
If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
If not, how should this be done?
Is there some sort of guide to accomplishing this that someone could point me to?

Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12927948#action_12927948 ] 

Michael Dick commented on OPENJPA-1860:
---------------------------------------

I'm not sure where the custom classloader fits in. 

What I thought Kevin proposed was having a template xml mapping file. Before creating an EntityManagerFactory your code would modify the xml mapping file with the correct table names (maybe copy it to the correct location, something like that). Is your custom classloader doing that modification? 

If you're operating over a set of known table names, maybe you could have a separate mapping file for each set. It would be easier to just copy a file or change the mapping file name in persistence.xml than to edit the file and replace tokens. 

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hugh resolved OPENJPA-1860.
---------------------------

    Resolution: Fixed

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12928080#action_12928080 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

Testing this without my custom classloader, (which I would have loaded in Main as well as well as in the openjpa.ClassResolver) uses the orm.xml correctly, so there is no bug there.

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>         Attachments: ORM.xml, persistence.xml, QueueData.java
>
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Kevin Sutter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12925825#action_12925825 ] 

Kevin Sutter commented on OPENJPA-1860:
---------------------------------------

Application Entity code gets loaded by either Container or OpenJPA specific classloaders.  We do this because OpenJPA does its own byte code enhancement and we need some control over how these classes are loaded.

>From your description, it sounds like you are running outside of a Container environment, correct?  When do you perform the OpenJPA Enhancement processing of the Entities?  Do you do this as part of your build process?  Or, do you rely on using OpenJPA as a java agent?

Not sure if this would work or not, but have you considered using a java agent for your byte code enhancement?  Depending on your environment, we may get into a race condition.  That is, who gets to do their enhancement first...

No easy answers on this one...
Kevin

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12926193#action_12926193 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

So I found out what a javaagent is, and I hooked my transformer into it and registered one for the startup.
It doesn't do the trick. I can see it loads and is called for almost all classes, but it never gets asked to transform the class I'm interested in.
Maybe it's the race condition you spoke of. Apparently M$ win this round. There's no portable way to modify the @Table name attribute of an OpenJPA  Entity class at runtime using a javaagent.

To answer your other questions Kevin. I'm letting OpenJPA act as the java agent at runtime. I don't convert them at build time. Would this make any difference?
My guess is that the @Table annotation would be stripped and I'd need to think of a new way to modify the byte code. Any clues?

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12925989#action_12925989 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

Thanks Kevin, I see the problem.
I changed my approach when I discovered the openjpa.ClassResolver plugin property and managed to get openJPA to use my classloader to load the class I'm interested in.
There's no need to replace the main classloader.
Yes, I'm running outside the container. I know this is not recommended by some, but my app is simple enough to manage the EM lifecycle & OpenEJB seems like overkill.

I'm not sure what you mean when you say a "java agent for my byte code enhancement" but I'm using bcm which I assume is the same thing?
What I discovered was that even though the @Table annotation name value is rewritten, it has no effect. Perhaps that's the race condition you mentioned or perhaps the rewrite is ineffective. What I saw was this order of events I logged:
getClassResolver(class org.apache.openjpa.jdbc.schema.DataSourceFactory, null)
getClassResolver(class org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory, sun.misc.Launcher$AppClassLoader@2bbd86)
getClassResolver(class org.apache.openjpa.persistence.jdbc.PersistenceMappingFactory, com.agilityapplications.turret.bcm.TableClassLoader@d557c2)
getClassResolver(class org.apache.openjpa.jdbc.meta.MappingRepository, com.agilityapplications.turret.bcm.TableClassLoader@d557c2)
Custom class com.agilityapplications.turret.jpa.QueueData to be transformed and loaded
QueueData constructor
QueueData constructor
QueueData constructor
getClassResolver(class org.apache.openjpa.jdbc.meta.MappingRepository, sun.misc.Launcher$AppClassLoader@2bbd86)
Custom class com.agilityapplications.turret.jpa.QueueData to be transformed and loaded
QueueData constructor

I don't understand why the constructor was run 4 times before the query actually runs or if this is related to my problem.
Should I be returning the modified Entity or should I call the classloader sent as my getClassResolver to further modify the class?

The finish line seems so close, but remains tantalisingly out of reach.


> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Kevin Sutter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12926291#action_12926291 ] 

Kevin Sutter commented on OPENJPA-1860:
---------------------------------------

As I look back on some of my questions, they didn't make sense for what you are trying to accomplish.  Since you are trying to dynamically change the @Table annotation at runtime, doing the OpenJPA byte code enhancement at build time would make no sense.  We would only be doing the byte code enhancement based on the ORM mappings defined in the static code.  So, forget about that idea.

Let's look at this differently...  Instead of attempting to modify the @Table annotations, how about modifying an orm.xml file?  All of the ORM annotations can be represented via an orm.xml file, which is referenced by your persistence.xml file.  So, if you have a template orm.xml file that could be modified based on your runtime considerations and then placed in the proper persistence archive location, then when the EMF is created, OpenJPA would reference this orm.xml file to know what the ORM mappings should be.  Instead of relying on the annotations.

Would this approach work for your scenario?



> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12929412#action_12929412 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

After a lot of permutations I've concluded that this works, but only in limited conditions:
1. Compiling with the PCEnhancerTask requires loading the openjpa.ClassResolver which requires access to any configuration resources needed to modify orm.xml. To work around this I put a dummy persistence-unit as the first persistence-unit in persistence.xml because it only attempts to do this for the first PU. This seems to be rather arbitrary but I suppose it help when you want to modify the classes at compile time.
2. The only ClassLoader method called which can be overridden to modify META-INF/orm.xml is public Enumeration<URL> getResources(String name) throws IOException;
None of the others are called when accessing orm.xml. This means that I need to write an actual file with the modifications I require at runtime and return the URL for that file from that method.
3. NamedQueries can't be used because for some reason they use the jar's META-INF/orm.xml without the openjpa.ClassResolver and the class annotations with openjpa.ClassResolver.
This works, but it's clumsy and awkward.

My question is, why isn't getResource and getResourceAsStream called by OpenJPA on the openjpa.ClassResolver to retrieve META-INF/orm.xml?

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>         Attachments: ORM.xml, persistence.xml, QueueData.java
>
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hugh updated OPENJPA-1860:
--------------------------

    Attachment: QueueData.java
                ORM.xml
                persistence.xml

Added persistence.xml and ORM.xml, both of which are in my jar files META-INF directory. Also added the Entity class.
The rewritten orm.xml is in the same directory with the jar and is identical except it has a valid table name.
If I change the code to use a Query with the exact jpaql statement instead of NamedQuery, it works fine.
Stack trace:
run:
Exception in thread "main" <openjpa-2.0.1-r422266:989424 fatal general error> org.apache.openjpa.persistence.PersistenceException: Invalid object name 'Dummy'. {prepstmnt 28814882 SELECT TOP 100 t0.ID, t0.Action, t0.Errors, t0.EventDateTime, t0.LastStatusChange, t0.Message, t0.OrgCode, t0.Resent, t0.SeqNumber, t0.Source, t0.Status, t0.TableName FROM Dummy t0 ORDER BY t0.ID DESC} [code=208, state=S0002]
FailedObject: SELECT qd FROM QueueData qd ORDER BY qd.id DESC [java.lang.String]
        at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4832)
        at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4792)
        at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
        at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:118)
        at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:70)
        at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.handleCheckedException(SelectResultObjectProvider.java:155)
        at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:40)
        at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1246)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
        at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
        at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
        at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
        at com.agilityapplications.turret.DataQueue.getQueueData(DataQueue.java:57)
        at com.agilityapplications.turret.DataQueue.logThem(DataQueue.java:158)
        at com.agilityapplications.turret.Main.<init>(Main.java:15)
        at com.agilityapplications.turret.Main.main(Main.java:22)
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: Invalid object name 'Dummy'. {prepstmnt 28814882 SELECT TOP 100 t0.ID, t0.Action, t0.Errors, t0.EventDateTime, t0.LastStatusChange, t0.Message, t0.OrgCode, t0.Resent, t0.SeqNumber, t0.Source, t0.Status, t0.TableName FROM Dummy t0 ORDER BY t0.ID DESC} [code=208, state=S0002]
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:273)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:257)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:70)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:1079)
        at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:278)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeQuery(JDBCStoreManager.java:1711)
        at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:268)
        at org.apache.openjpa.jdbc.sql.SelectImpl.executeQuery(SelectImpl.java:471)
        at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:396)
        at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:354)
        at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:94)
        at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:34)
        ... 11 more
NestedThrowables:
java.sql.SQLException: Invalid object name 'Dummy'.
        at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
        at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
        at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
        at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
        at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
        at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:776)
        at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:280)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:1077)
        at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:278)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeQuery(JDBCStoreManager.java:1711)
        at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:268)
        at org.apache.openjpa.jdbc.sql.SelectImpl.executeQuery(SelectImpl.java:471)
        at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:396)
        at org.apache.openjpa.jdbc.sql.SelectImpl.execute(SelectImpl.java:354)
        at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.open(SelectResultObjectProvider.java:94)
        at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:34)
        at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1246)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:861)
        at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:792)
        at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
        at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:288)
        at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
        at com.agilityapplications.turret.DataQueue.getQueueData(DataQueue.java:57)
        at com.agilityapplications.turret.DataQueue.logThem(DataQueue.java:158)
        at com.agilityapplications.turret.Main.<init>(Main.java:15)
        at com.agilityapplications.turret.Main.main(Main.java:22)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>         Attachments: ORM.xml, persistence.xml, QueueData.java
>
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12927665#action_12927665 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

Oddly, this doesn't work for NamedQueries.

I've installed my custom classloader at startup as well as adding it to the openjpa.ClassResolver setting.
A query works, but a namedquery fails with "PersistenceException: Invalid object name" for the tablename.
Evidently NamedQueries don't read the orm.xml. Perhaps this is a bug?

How should I go about making this work for the namedqueries as well?

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Reopened: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hugh reopened OPENJPA-1860:
---------------------------


Doesn't work for NamedQueries

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12926817#action_12926817 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

Thank you very much.

Although it was a bit difficult to convince the custom ClassLoader to use the external resource after I rewrite it. And then to build the jar in netbeans with the right sort of Class-Path entries, your suggestion worked. ( I wanted to use the -jar argument )

I spent a lot of time looking for this solution and I'm really grateful. I'll post your idea on a few of the other forums I asked this question on.

Thorbjørn Ravn Andersen (slf4j author) was asking this same question on stackoverflow and told me he never found a solution.

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Hugh (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12928073#action_12928073 ] 

Hugh commented on OPENJPA-1860:
-------------------------------

Michael,
I have a template which I keep in META-INF/orm.xml
This is inside a jar file so I can't modify it directly. I have to intercept the getResource request in my custom classloader and write my custom xml.orm based on information (the table name) that's only available at runtime. I then return this resource URL.
Business may add new tables at any time and deploy a new instance of the application to service that new table so I have no idea about table names at compile time.

Kevin,
I'm using OpenJPA 2.0.1 and I'll get you the rest of the information shortly.
I'll do a test to see if orm.xml is ignored without any modifications from me for NamedQueries as well if I have time.

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?

Posted by "Kevin Sutter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-1860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12927950#action_12927950 ] 

Kevin Sutter commented on OPENJPA-1860:
---------------------------------------

Hugh,
We're going to need a bit more information to help with this...  From an O/R Mapping perspective, there should be no difference between processing a NamedQuery vs a normal JPQL Query.  Unless something is being cached somewhere...

Could you please provide further information on your environment?  The persistence.xml would also be helpful.  The complete exception text with call stack would be good.  What version of OpenJPA are you using?

Thanks,
Kevin

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>
>                 Key: OPENJPA-1860
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1860
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>
> I have written a custom classloader and I can't work out how to get OpenJPA to use it to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader() at startup before loading any EntityManager and it seems to load the OpenJPA classes and a lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (http://openjpa.208410.n2.nabble.com/Dynamic-Table-value-td5645906.html)
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.