Hi Davide,
Thanks for reply.
Below is the code snippet of what I am trying to do.
Code:
@Entity
public class Employee extends AbstractModel{
private String name;
private int age;
private Department department;
@Column(name="emp_name", nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="age", nullable=false)
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name="dept_id", nullable=false)
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
}
Code:
@Entity
public class Department extends AbstractModel {
private String name;
@Column(name="dept_name", nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
And the JUnit Test Class:
Code:
public class EmployeTest {
private EntityManager getEntityManager() {
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(ApplicationConstants.PERSISTENCE_UNIT_NAME);
return entityManagerFactory.createEntityManager();
}
@Test
public void findEmployee() {
StringBuilder queryString = new StringBuilder();
queryString.append("select e from Employee e where e.department.name=:name");
EntityManager entityManager = getEntityManager();
Query query = entityManager.createQuery(queryString.toString());
query.setParameter("name", "x");
System.out.println(query.getResultList().size());
}
}
I have removed the unnecessary code from classes and kept just the important one.
When i run the test case, I get the error like :
Code:
java.lang.UnsupportedOperationException: Queries on embedded/associated entities are not supported yet.
at org.hibernate.ogm.datastore.mongodb.query.parsing.impl.MongoDBPropertyHelper.convertToPropertyType(MongoDBPropertyHelper.java:37)
at org.hibernate.hql.ast.spi.SingleEntityQueryBuilder.addComparisonPredicate(SingleEntityQueryBuilder.java:83)
at org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.addComparisonPredicate(SingleEntityQueryRendererDelegate.java:231)
at org.hibernate.hql.ast.spi.SingleEntityQueryRendererDelegate.predicateEquals(SingleEntityQueryRendererDelegate.java:209)
at org.hibernate.hql.ast.render.QueryRenderer.predicate(QueryRenderer.java:5197)
at org.hibernate.hql.ast.render.QueryRenderer.searchCondition(QueryRenderer.java:4871)
at org.hibernate.hql.ast.render.QueryRenderer.whereClause(QueryRenderer.java:2347)
at org.hibernate.hql.ast.render.QueryRenderer.querySpec(QueryRenderer.java:2202)
at org.hibernate.hql.ast.render.QueryRenderer.queryExpression(QueryRenderer.java:2105)
at org.hibernate.hql.ast.render.QueryRenderer.queryStatement(QueryRenderer.java:1744)
at org.hibernate.hql.ast.render.QueryRenderer.queryStatementSet(QueryRenderer.java:1657)
at org.hibernate.hql.ast.render.QueryRenderer.statement(QueryRenderer.java:653)
at org.hibernate.hql.ast.spi.QueryRendererProcessor.process(QueryRendererProcessor.java:51)
at org.hibernate.hql.QueryParser.parseQuery(QueryParser.java:82)
at org.hibernate.ogm.datastore.mongodb.query.parsing.impl.MongoDBBasedQueryParserService.parseQuery(MongoDBBasedQueryParserService.java:40)
at org.hibernate.ogm.query.impl.OgmQueryTranslator.getQuery(OgmQueryTranslator.java:168)
at org.hibernate.ogm.query.impl.OgmQueryTranslator.getLoader(OgmQueryTranslator.java:130)
at org.hibernate.ogm.query.impl.OgmQueryTranslator.list(OgmQueryTranslator.java:125)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:231)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
at test.EmployeTest.findEmployee(EmployeTest.java:62)
As you can see, I have two entities and they are coupled with Many to One relationship.
Kindly help if i need to correct my data model structure.
Thanks ..