-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kundera will not scan entities from a JAR file #90
Comments
Did you try adding jar file undera -Vivek |
Hi Vivek - Thanks - I admit I wasn't aware of that option - however its not ideal as the name and location of the class file in production will change, so its not the best solution I feel. My jar file will move around between development, staging and live servers, and change name between versions, although I do realise of course that I could alleviate the version issue by filtering the files at build time in maven. Also, according to the jpa spec, my reading is that should be enough to find classes, and jar-file is used to search specific jar-files rather in the same way as kundera.annotations.scan.package, these jar files should also be specified relative to the directory or jar that contains the root of the persistence unit, so for example lib/core-1.2.3-SNAPSHOT.jar. Daniel |
Hi, Here are some excerpt about loading classes from JPA specification: /**
/**
/**
Scanning complete classpath for entities is somewhat not desirable. I hope am not missing anything on this front. Feel free to correct, if i missed something. -Vivek |
I'm reading persistence-2_0-final-spec.pdf - specifically 8.2.1.6.3 and 8.2.1.6.4. "A list of named managed persistence classes may be specified instead of, or in addition to, the JAR files and mapping files. Any mapping metadata annotations found on these classes will be processed ... The class element is used to list a managed persistence class." Where was the above from? I agree that scanning complete classpaths isn't desirable (although I've never had this problem before with say hibernate) - however I'd hope not to have to name the jar files either. Ideally I should just list the class files that contain my entities, which would be loaded as normal. My reading of the spec is that this is allowed. |
It was from 9.5 section. i am on same spec :) As you mentioned for 8.2.1.x section, here it is: "The managed persistence classes may either be contained within the root of the persistence unit; or they With Hibernate, did you work in annotation way or defined any orm.xml or hbm.xml ? As my understanding is without them or not defining them within "mapping-class" or "mapping-file" tag, it should complain about it, unless "managed instances" are not in the root folder of persistence.xml Would love to hear your point on this. -Vivek |
Just noticed that you mentioned: That is what i am saying, should be the way. So if you have defined "mapping-class" and mapped your managed instances with them, they should automatically get loaded, provided your "jar" containing them should be in classpath! -Vivek |
Please share your persistence.xml. Does it contain "class" tag mapping for managed instances (available in core.jar). Then Kundera should be able to load them provided that those jars are available with "Thread.currentThread().getContextClassLoader()". Or |
For a moment there I thought I'd done something dumb like not included the jar in the classpath, however it would never reach persist() if I had. Not knowingly using OSGI, no - I'm using spring, but spring-modules isn't involved. Given what you are saying I'm worried that I've done something wrong, so I'll build a much smaller simpler example to replicate if that's ok, as I think I might be wasting your time otherwise, My persistence.xml file:
|
Hi Daniel, Can you share your source code to have a look and test it at my end please? -Vivek |
Hi Daniel, -Vivek |
Could you please try with latest "trunk". I have added a fix for this. Please verify. -Vivek |
Great - I've actually just built a smaller example to show the issue. I'll try it with the trunk as you suggest. Thanks for your help by the way :) |
Thanks to you for pointing towards the issue :) Process was as per jpa spec, but Kundera missed out those scanned classes. It should work now. -Vivek |
OK, I've pushed an example to https://github.com/dstrawson/kunderatest. It also demonstrates issue 91, although I've not gone back to that yet, which I will do when I have this working. I've pulled trunk / built / installed your new version and updated my dependencies / rebuilt but not managed to get it working with this example, still the same issue - when I built it for the first time it failed a UT however, so will need to go back and see why it failed the test. |
Thanks. Will have a look and get back to you. -Vivek |
Hi Vivek - When I build kundera-cassandra 2.0.8-SNAPSHOT I get the following : <<< FAILURE! |
Try with mvn clean install -Dmaven.test.skip=true |
Sure, that works, however I cannot get that fix to show itself I'm afraid so was assuming that the broken test might have something to do with it. |
There is where I am with 2.0.8-SNAPSHOT:
|
If I only include elements in persistence.xml Kundera fails to pick up the entity classes. I think If I understood you correctly you were saying that this should work ok.? Yes. This is what i believe should work. i will have a look with your sample example. Till then, as a workaround other 2 options should be workable for you. -Vivek |
Ok. Added a fix for this and verified with your github example. Please verify at your end. -Vivek |
Thanks - that's fixed it - I'm getting a different problem now HOWEVER its more an issue with the application server than Kundera, although it should probably be considered as an improvement:
I saw this before, I think what's going on is that I have the same entry duplicated in my classpath for some as yet unknown reason and the code doesn't deal with it very well, I've no idea why the classpath has duplications however the fix I've made is:
But like I say I will try and find the reason for the duplicates |
Ideally there should not be 2 classes available with same complete name.I hope, same classes are not unpacked in root folder? -Vivek |
Hi, -Vivek |
I have tested my code with 2.7.1 and it worked okay. But after updating to 2.8.1, Kundera failed to search my entity classes given in persistence.xml. Nothing has changed on my code.
|
Could you please provide a sample project for this? Though, I have verified with https://github.com/dstrawson/kunderatest . Modified persistence.xml for
Test1.java
modify core-package and api-package for pom.xml to point to 2.8.1 release Working fine. -Vivek |
I used Spring for JPA. spring-data-repo.xml <context:property-placeholder location="classpath:WEB-INF/spring/*.properties " />
<context:component-scan base-package="com.methodikos.domain" />
<context:annotation-config />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<!-- Entity Manager Factory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="hbaseMethodikosPu" />
<!-- <property name="packagesToScan" value="com.methodikos.domain" /> -->
<!-- <property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
</property> -->
</bean>
<jpa:repositories base-package="com.methodikos.data.repository"></jpa:repositories>
<!-- JPA Transaction Manager -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- Annotation Driven -->
<tx:annotation-driven transaction-manager="transactionManager"/> Test code @ContextConfiguration(
locations = {
"classpath:WEB-INF/spring/spring-data-repo.xml"
})
@RunWith(SpringJUnit4ClassRunner.class)
public class HBaseTest {
private final Logger logger = LoggerFactory.getLogger(HBaseTest.class);
@Autowired
EntityManagerFactory emf;
@Test
public void getDataTest() {
EntityManager em = emf.createEntityManager();
// No entity found by the name: TestPojo
Query q = em.createQuery("Select t from TestPojo t where t.id='1'");
List<TestPojo> results = q.getResultList();
for (TestPojo result : results) {
logger.debug("{}, {}, {}", result.getCol1(), result.getCol2(), result.getCol3());
}
}
} TestPojo is domain object from another maven project @Entity
@Table(name = "test", schema = "test@hbaseMethodikosPu")
public class TestPojo {
@Id
String id;
@Column(name = "col1")
private String col1;
@Column(name = "col2")
private String col2;
@Column(name = "col3")
private String col3;
public String getCol1() {
return col1;
}
public void setCol1(String col1) {
this.col1 = col1;
}
public String getCol2() {
return col2;
}
public void setCol2(String col2) {
this.col2 = col2;
}
public String getCol3() {
return col3;
}
public void setCol3(String col3) {
this.col3 = col3;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
} persistence.xml <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="hbaseMethodikosPu">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<!-- <class>com.methodikos.domain.Pavement</class> -->
<jar-file>../methodikos-shared/target/methodikos.jar</jar-file>
<!-- <exclude-unlisted-classes>true</exclude-unlisted-classes> -->
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9160" />
<property name="kundera.keyspace" value="methodikos" />
<property name="kundera.dialect" value="hbase" />
<property name="kundera.client.lookup.class" value="com.impetus.client.hbase.HBaseClientFactory" />
<property name="kundera.cache.provider.class"
value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
<!-- <property name="index.home.dir" value="./lucene" /> -->
<property name="kundera.ddl.auto.prepare" value="create" />
<property name="kundera.client.property" value="hbaseMethodikos.xml" />
<!-- <property name="kundera.annotations.scan.package" value="com.methodikos.domain" /> -->
<!-- <property name="" value="../methodikos-shared/target/methodikos.jar"/> -->
</properties>
</persistence-unit>
</persistence> Log when I use 2.8.1
Log when I use 2.7.1
Log seems to be same for both but 2.7.1 is able to find my entity and 2.8.1 not. I am using Java 1.7. I checked dependency change between 2.7.1 and 2.8.1 but found nothing special, although I am thinking there are some dependency issues. Thank you |
Please email sample project to me at [email protected] |
Hi -
Not sure if this is a bug or a feature request. If you take the view that this is a feature then I understand!
My entities are in a separate file (core.jar) which is included in my application as a dependency. This is because it is shared between modules. Kundera doesn't find them - neither when I use in the persistence.xml file, nor when I use kundera.annotations.scan.package. As soon as I un-jar the core.jar file into my classes/ folder, everything starts working as expected.
Setup:
Kundera-2.0.7
Cassandra-1.1.2
Maven
Sping / CXF
The text was updated successfully, but these errors were encountered: