dbTalk Databases Forums  

Using JE DPL inside Tomcat

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss Using JE DPL inside Tomcat in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Alex Karpoff
 
Posts: n/a

Default Using JE DPL inside Tomcat - 07-23-2006 , 04:11 AM






Hello,

I have a strange problem with JE 3. This code works perfectly when I
run junit tests of my model classes (including AutoFirm), but it does
work running inside Tomcat or Resin (no matter).

// My code:

@Entity
public class AutoFirm {

@PrimaryKey
private int id;
....
}

....
envConfig.setAllowCreate( true );
envConfig.setTransactional( true );
....
StoreConfig storeConfig = new StoreConfig();
storeConfig.setAllowCreate( true );
storeConfig.setTransactional( true );

entityStore = new EntityStore( env, "testing", storeConfig );

PrimaryIndex<Integer, AutoFirm> primaryIndex =
entityStore.getPrimaryIndex( Integer.class, AutoFirm.class );

// getPrimaryIndex cause following exception:

Message: Not an entity class: com.rasklad.autodb.AutoFirm
- com.sleepycat.persist.impl.Store : checkEntityClass : 768
- com.sleepycat.persist.impl.Store : getPrimaryIndex : 249
- com.sleepycat.persist.EntityStore : getPrimaryIndex : 237

Also I tried to get class meta data for AutoFirm.class:

String className = AutoFirm.class.getName();
Class<?> type = Class.forName( className );
AnnotationModel annotationModel = new AnnotationModel();
ClassMetadata classMetadata = annotationModel.getClassMetadata(
className );

In unit tests it is not null. But when running this check code inside
servlet classMetadata become null.

Please impart the solution of this problem. Thank you


Reply With Quote
  #2  
Old   
mark.hayes (AT) oracle (DOT) com
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-24-2006 , 11:17 PM






Hello Alex,

Alex Karpoff wrote:

Quote:
I have a strange problem with JE 3. This code works perfectly when I
run junit tests of my model classes (including AutoFirm), but it does
work running inside Tomcat or Resin (no matter).
We have not tested DPL inside of Tomcat or Resin. The only requirement
is that the annotations must be available in the Tomcat/Resin
container. Could you please try the following test when running under
Tomcat/Resin to make sure that the DPL annotations are available?:

---
import com.sleepycat.persist.model.Entity;

Entity annotation = AutoFirm.class.getAnnotation(Entity.class);
System.out.println("annotation available: " + (annotation != null));
---

This will tell us a little more about what is happening.

Thanks,
Mark



Reply With Quote
  #3  
Old   
Alex Karpoff
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-25-2006 , 12:54 AM



Hello, Mark

Thank you for paying attention to my problem.

Quote:
We have not tested DPL inside of Tomcat or Resin. The only requirement
is that the annotations must be available in the Tomcat/Resin
container. Could you please try the following test when running under
Tomcat/Resin to make sure that the DPL annotations are available?:
I already had the test of annotations availability.
It is similar to your one:

// ----
Class<Entity> annotationClass = Entity.class;
out.print( AutoFirm.isAnnotationPresent( annotationClass ) );

Entity annotation = AutoFirm.getAnnotation( annotationClass );
out.print( "=" );
out.print( annotation.version() );
// ----

For @Entity( version = 3 ) it returns true=3.
Annotations are available.



Reply With Quote
  #4  
Old   
Alex Karpoff
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-25-2006 , 01:51 AM



Mark.

I forgot to say that I run all this tests on Tomcat & Resin without
Apache and any changes in default config files except mapping to my web
applications.

Also environment that opened inside servlet container is initialized
inside too. No external environment creation.

Thanks


Reply With Quote
  #5  
Old   
mark.hayes (AT) oracle (DOT) com
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-25-2006 , 04:54 PM



Alex Karpoff wrote:
Quote:
Hello, Mark

Thank you for paying attention to my problem.
You're welcome.

I think the solution is to place the je.jar file in the same servlet
classpath location as your application/servlet classes. For example,
when using Tomcat, place je.jar in your servlet's WEB-INF/lib
directory. (I assume your servlet classes are in WEB-INF/classes or
WEB-INF/lib.) Do not put je.jar in any other classpath location, for
example, shared/lib.

If je.jar is in a shared location, it will not have access to your
servlet classes. This is because shared classes are loaded under a
different classloader than servlet classes. Of course, the DPL classes
in JE need access to the persistent classes in your servlet in order to
introspect them.

I wrote a small test, and when I put je.jar in shared/lib I get the
error you reported. When I put je.jar in WEB-INF/lib, the error goes
away and I am able to get/put objects.

Please let me know if this doesn't solve the problem.

Mark



Reply With Quote
  #6  
Old   
Alex Karpoff
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-26-2006 , 04:33 AM



Hello, Mark

You are absolutely right. I keep all jar-files in sharedlib folder.
Your recommendation to move them to WEB-INF/lib helps me to run my
webapp.

But for my situation this solution is not very beautiful. I have
several webapps. They use common library that wraps berkley db engine.
It seems to me that such dependence forces putting this library code
and je.jar into every webapp WEB-INF/lib folder

Thank you for your consultation
Regads, Alex

PS. I've found memory leak on multiple environment open-close
operation. May be it is good idea to start discussion in new thread?


Reply With Quote
  #7  
Old   
Art S. Kagel
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-26-2006 , 08:57 AM



Alex Karpoff wrote:
Quote:
Hello, Mark

You are absolutely right. I keep all jar-files in sharedlib folder.
Your recommendation to move them to WEB-INF/lib helps me to run my
webapp.

But for my situation this solution is not very beautiful. I have
several webapps. They use common library that wraps berkley db engine.
It seems to me that such dependence forces putting this library code
and je.jar into every webapp WEB-INF/lib folder
Keep the files in your sharedlib folder and place links in each WEB-INF/lib
folder. Then you don't have to worry about one or another file being the
wrong version.

Art S. Kagel


Reply With Quote
  #8  
Old   
Alex Karpoff
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-28-2006 , 02:14 AM



Art, thank you for advice.

But there are two questions:
1. How can I place links in Windows?
2. How many times will be, for example, je.jar loaded by servlet
container?

Regards,
Alex


Reply With Quote
  #9  
Old   
mark.hayes (AT) oracle (DOT) com
 
Posts: n/a

Default Re: Using JE DPL inside Tomcat - 07-28-2006 , 04:29 PM



Alex Karpoff wrote:

Quote:
But for my situation this solution is not very beautiful. I have
several webapps. They use common library that wraps berkley db engine.
It seems to me that such dependence forces putting this library code
and je.jar into every webapp WEB-INF/lib folder
I'm sorry Alex, I don't know of any other solution. The JE DPL needs
to instantiate your classes and perform other types of introspection.
I think because of the way class loaders work, and because each servlet
is loaded under a different class loader, the JE jar file and your
classes must be loaded under the same class loader. This means they
will be duplicated in memory, and I believe this is true whether you
use links to a shared file or not.

I will continue to think about other possible solutions.

Quote:
Thank you for your consultation
Regads, Alex

PS. I've found memory leak on multiple environment open-close
operation. May be it is good idea to start discussion in new thread?
Yes, please post new requests and issues to the Oracle forum that was
announced on this group:

http://forums.oracle.com/forums/forum.jspa?forumID=273

Thanks,
Mark



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.