I'm using glassfish 3.1.2. I have managed to get this working though.

What I ended up doing was explicitly putting the velocity jar file in my 
domains/domain1/lib folder under glassfish . This then resulted in a new class 
loader exception about commons.lang.StringUtils. So I put commons-lang-2.6 jar 
in the lib folder as well - now all works fine.

In my maven dependency hierarchy, I see that velocity-1.6.3 references 
commons-lang-2.4. I am also using commons-configuration-1.9 which references 
commons-lang-2.6. Maven is telling me it is omitting the commons-lang-2.4 
because of the 2.6 conflict. All this seems related to me, but I'm not sure how.

If there's anything else you would like me to try at my end, I'll be glad to do 
so. It doesn't seem like I should have to go through all these hoops when I'm 
using maven to manage my dependencies for me.

I'm including my pom.xml file as well in case that's useful to you.

And thanks all for the great help so far…


<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <groupId>CayenneServiceTemplate</groupId>
  <artifactId>CayenneServiceTemplate</artifactId>
  <version>1.0.0</version>
  <dependencies>
  <dependency>
  <groupId>org.apache.cayenne</groupId>
  <artifactId>cayenne-server</artifactId>
  <version>3.1B2</version>
  </dependency>
  <dependency>
  <groupId>org.jdom</groupId>
  <artifactId>jdom</artifactId>
  <version>1.1.3</version>
  </dependency>
  <dependency>
  <groupId>com.sun.jersey</groupId>
  <artifactId>jersey-grizzly2</artifactId>
  <version>1.12</version>
  </dependency>
  <dependency>
  <groupId>postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>9.1-901.jdbc4</version>
  </dependency>
  <dependency>
  <groupId>axis</groupId>
  <artifactId>axis-jaxrpc</artifactId>
  <version>1.4</version>
  </dependency>
  <dependency>
  <groupId>axis</groupId>
  <artifactId>axis</artifactId>
  <version>1.4</version>
  </dependency>
  <dependency>
  <groupId>com.google.code.gson</groupId>
  <artifactId>gson</artifactId>
  <version>2.2.2</version>
  </dependency>
  <dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>jackson-jaxrs</artifactId>
  <version>1.9.12</version>
  </dependency>
  <dependency>
  <groupId>org.codehaus.jackson</groupId>
  <artifactId>jackson-xc</artifactId>
  <version>1.9.12</version>
  </dependency>
  <dependency>
  <groupId>commons-configuration</groupId>
  <artifactId>commons-configuration</artifactId>
  <version>1.9</version>
  </dependency>
  <dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.2.2</version>
  </dependency>

  </dependencies>
</project>

On Apr 16, 2013, at 1:51 PM, Andrus Adamchik 
<[email protected]<mailto:[email protected]>> wrote:

SQLTemplate backend relies on Velocity. EJBQLQuery backend relies on 
SQLTemplate. No other queries rely on Velocity or SQLTemplate, and Java class 
loading is lazy. So Velocity is likely the culprit.

So which Glassfish version do you have? Maybe I can try a basic test in an 
isolated environment.

Andrus

On Apr 16, 2013, at 1:26 PM, Rick Bonnett 
<[email protected]<mailto:[email protected]>> wrote:
OK. One more level down the rabbit hole now…

now that I have velocity seemingly loading, I get this in the stack trace:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
org.apache.cayenne.access.jdbc.SQLTemplateProcessor
at 
org.apache.cayenne.access.jdbc.SQLTemplateAction.performAction(SQLTemplateAction.java:102)
at 
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:280)
at 
org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:442)
at 
org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:70)
at 
org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:415)
at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:877)
at 
org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:412)
at 
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:122)
at org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:758)
at 
org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1009)
at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:748)
at 
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
at 
org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
at 
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
at 
com.mesca.services.AccessorialService.allAccessorialRows(AccessorialService.java:90)

I'm very puzzled as to why other Cayenne classes and methods sen to work fine. 
For example, this code works within the same web service:

ServerRuntime cayenneRuntime = new 
ServerRuntime("cayenne-cayenne-service-template.xml");
ObjectContext context = cayenneRuntime.getContext();


SelectQuery select1 = new SelectQuery(Accessorial.class);
Collection<Accessorial> accessorials = context.performQuery(select1);

Just in general, I've yet to get a SQLTemplate or EJBQLQuery to work when 
running in glassfish, although using SelectQuery has given me no problems.



On Apr 16, 2013, at 9:59 AM, Mike Kienenberger 
<[email protected]<mailto:[email protected]><mailto:[email protected]>> 
wrote:

My first guess would be that you have more than one velocity jar files
in the classpath.
I guess a second possibility is that you have no velocity jar files in
the classpath.

We have an in-house findClass.jsp (backed by a ClassPath bean) which
we use for problems like this to identify all definitions of a class
in the classpath.   Unfortunately, I don't have permission to share
this.

But you could probably come up with something similar:


Here's a jsp that looks like it identifies the first definition of a class.
http://mcpaint.tistory.com/13


Here's how to show all resources
http://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/

You'd probably want to combine the two.


Here's something else I came across while trying to find an example of
what you needed.  Not sure how easy it would be to integrate with your
app.

http://classpathhelper.sourceforge.net/

On Tue, Apr 16, 2013 at 8:38 AM, Rick Bonnett <[email protected]> wrote:
I'm trying to use SQLTemplate queries and running into a strange problem. This 
snippet works fine if I run it in a plain Java application, but fails if I then 
use it within a web service running under Glassfish.
In both cases I am using the same cayenne metadata files. I have also noticed 
the same issue when using EJBQL queries.


ServerRuntime cayenneRuntime = new 
ServerRuntime("cayenne-cayenne-service-template.xml");
ObjectContext context = cayenneRuntime.getContext();


SQLTemplate  sql = new SQLTemplate(Accessorial.class,"SELECT * FROM 
live.tbl_accessorials");
String pgSql = "SELECT * FROM live.tbl_accessorials";
sql.setTemplate(PostgresAdapter.class.getName(), pgSql);
Collection<Accessorial> accessorials = context.performQuery(sql);


I have tried this both with and without the Postgres specific template - same 
result either way. Works fine in a console app, fails running under the web 
server.

This seems to be the relevant section of the stack trace:

Caused by: java.lang.NoClassDefFoundError: 
org/apache/velocity/runtime/parser/ParseException
at 
org.apache.cayenne.access.jdbc.SQLTemplateAction.performAction(SQLTemplateAction.java:102)
at 
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:280)
at 
org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:442)
at 
org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:70)
at 
org.apache.cayenne.access.DataDomainQueryAction$2.transform(DataDomainQueryAction.java:415)
at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:877)
at 
org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:412)
at 
org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:122)
at org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:758)
at 
org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:1009)
at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:748)
at 
org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:350)
at 
org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:106)
at 
org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:93)
at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:989)
at org.apache.cayenne.access.DataContext.performQuery(DataContext.java:978)
at 
com.mesca.services.AccessorialService.allAccessorialRows(AccessorialService.java:83)

Any ideas on what I am missing here?

Thanks
Rick


Reply via email to