开发者

EJB entity beans JAR & RESTeasy

开发者 https://www.devze.com 2023-03-06 17:36 出处:网络
I am having trouble getting my entity beans to connect correctly to MySQL. Here\'s my set up: JBOSS: 6

I am having trouble getting my entity beans to connect correctly to MySQL. Here's my set up:

JBOSS: 6

UBUNTU: 11.04

EJB: 3.1

I am currently trying to access entity beans via a JNDI remote call to a JARed session bean in the root of my EAR file.

My Entity beans map correctly to my database and work in one EAR file however I want to use the same entity beans in another EAR file in the same container so I have JARed my entity beans and I pull them into my second EAR file using my build script. I am pulling the exact same persistance.xml file as my first EAR file and it points to the same data source XML in the root of my deploy directory. I can define my persistence context and access my entity beans without error and I can compile and deploy my JBoss server without any exceptions. However I get this error when I try to access the entity beans after the container has deployed:

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [SELECT u FROM User u WHERE u.accountId=:accountId]

This is the query I am using:

List<User> users = entityManager.createQuery("SELECT u FROM User u WHERE u.accountId=:accountId")
        .setParameter("accountId", accountId)
        .getResultList(); 

Can anyone tell me if:

  1. there is an issue with开发者_如何学Go JARing entity beans
  2. does RESTeasy need some special config to deal with entity beans
  3. is it even possible to use JARed entity beans
  4. could there be a config conflict if I am accessing the same datasource using two separate instances of the same entity beans in the same container

Thanks in advance for any help with this. I am really stuck.

ADDED (20/05/2011):

So I have now consolidated my entity and session beans into one jar and have altered the persistence.xml so include the auto detect property suggested by Nayan below:

<property name="hibernate.archive.autodetection" value="class"/>

but to no avail. I have the JAR registered in my application.xml and have added the JAR to the classpath in my build script.

Would it make any sense to put the JAR file into the root of the deploy directory and try to access it from there?


In your EAR, it seems that the entities packaged in jar aren't recognized, also check whether jar is present in classpath.

Try adding <property name="hibernate.archive.autodetection" value="class"/> in persistence.xml.

Else, try including class for persistent unit.

<persistence-unit name="unitName">
    <class>com.package.User</class>
    ...
 </persistence-unit>


The issue was with the location of my persistence.xml file. I have the persistence.xml file in a JAR with my sessions beans not with my entity beans where it was needed. Problem solved!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号