-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate does not scan for entities outside jar files
PostPosted: Tue Jan 24, 2017 4:45 pm 
Newbie

Joined: Tue Jan 24, 2017 4:30 pm
Posts: 3
In certain cases Hibernate won't find JPA entities and simply will fail with java.lang.IllegalArgumentException: Not an entity: class com.github.vok.example.crud.personeditor.Person. Even though it *is* a correctly annotated JPA entity and works properly when referenced via the class element. I tried to employ
Code:
<property name="hibernate.archive.autodetection" value="class, hbm"/>

and
Code:
<exclude-unlisted-classes>false</exclude-unlisted-classes>

with no success. I think that Hibernate only scans jar files on classpath and ignores folders with classes. This is especially on development environments where Jetty is launched using a simple main class.

If this is the case, can I somehow force Hibernate to also scan classpath directories for annotated classes?

My project is located in https://github.com/mvysny/vaadin-on-kotlin - just open it in your IDE and then launch the Server class (located in vok-example-crud/src/test/java/com/github/vok/example/crud/Server.kt). You'll need the Kotlin plugin installed. If you are interested, I can prepare a very simple Maven project which also demonstrates the issue.

Thank you very much for any pointer in this regard.


Top
 Profile  
 
 Post subject: Re: Hibernate does not scan for entities outside jar files
PostPosted: Wed Jan 25, 2017 2:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Check out this article for more details:

- How to use external XML mappings files (outside of JAR) with JPA and Hibernate


Top
 Profile  
 
 Post subject: Re: Hibernate does not scan for entities outside jar files
PostPosted: Wed Jan 25, 2017 3:25 am 
Newbie

Joined: Tue Jan 24, 2017 4:30 pm
Posts: 3
Thank you, but setting orm.xml would not help to auto-discover my JPA @Entities located in the classes/ folder. I eventually used the AnnotationDetector to scan for classes:

Code:
    val entities = mutableListOf<Class<*>>()
    AnnotationDetector(object : AnnotationDetector.TypeReporter {
        override fun reportTypeAnnotation(annotation: Class<out Annotation>?, className: String?) {
            entities.add(Class.forName(className))
        }

        override fun annotations(): Array<out Class<out Annotation>> = arrayOf(Entity::class.java)
    }).detect("com.github")

    VaadinOnKotlin.entityManagerFactory = Persistence.createEntityManagerFactory("sample", mapOf(AvailableSettings.LOADED_CLASSES to entities))


I have used the detector which is built-in in the atmosphere jar file; but you can use perhaps https://github.com/rmuller/infomas-asl or others as stated here: http://stackoverflow.com/questions/2591 ... at-runtime
The full code example is located here: https://github.com/mvysny/vaadin-on-kot ... /Server.kt


Top
 Profile  
 
 Post subject: Re: Hibernate does not scan for entities outside jar files
PostPosted: Wed Jan 25, 2017 3:33 am 
Newbie

Joined: Tue Jan 24, 2017 4:30 pm
Posts: 3
The full answer may be found here: http://stackoverflow.com/a/41845759/377320


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.