0

I am migrating my project from Jboss5 to Jboss7 and am having some issues with the Hibernate autoscanning of entities. In my persistence.xml, if I list them all individually as so:

<class>com.xxx.test.Something</class>

the entity is registered and works fine. However, if I use the annotations in the entity class, like so:

@Entity
@Table(name="something")
...

I get an unknown entity exception. I've done a lot of reading about possible class path problems (Is there a way to scan JPA entities not to declare persistent classes in a persistence.xml file?), but these don't seem to apply to me, as my class path in my jar is configured correctly, according to the thread above.

My xxx.jar contains a com directory and a META-INF directory. The com contains subfolders which have my classes, and the META-INF contains the persistence.xml (My persistence.xml is listed below)

I eventually found this - http://learningviacode.blogspot.com/2013/03/persistencexml.html

which says

"JPA states that the annotated classes will be auto-discovered in an Enterprise environment, but in a Standalone environment we need to specify the entities using the element". I currently deploy my jboss using standalone.bat, so it seemed to explain my problem.

I was doing some research on deploying with other batch files and I found this: https://docs.jboss.org/author/display/AS7/Operating+modes which says,

"Running a standalone server is better suited for most development scenarios. Any individual server configuration that can be achieved in a managed domain can also be achieved in a standalone server, so even if the application being developed will eventually run in production on a managed domain installation, much (probably most) development can be done using a standalone server."

This leads me to believe that I can, indeed, use the annotations in a standalone environment, assuming the entity registration using annotations is a server configuration.

All in all, I am not sure how to proceed, or how to have my entities auto scanned using annotations.

Here is my persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence     http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="xxxPersistenceContext">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/xxxDS</jta-data-source>
    <!-- <class>com.xxx.test.Something</class>    -->
    <exclude-unlisted-classes>false</exclude-unlisted-classes>  

    <properties>
        <property name="hibernate.cache.use_second_level_cache" value="true" />
        <property name="hibernate.id.new_generator_mappings" value="false"/>
        <property name="hibernate.classloading.use_current_tccl_as_parent" value="false"/>
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.archive.autodetection" value="class, hbm" />

    </properties>
</persistence-unit>

Any help on how to get autoscanning to work for Jboss7 would be greatly appreciated. Thanks!

Requested Additions

I am using hibernate 4.0.1

Jboss start log: https://www.dropbox.com/s/4uiydjw44hwyjer/jboss7-startup.txt?dl=0

Community
  • 1
  • 1
arjun kumar
  • 183
  • 3
  • 14

0 Answers0