Problemas com Joins no Hibernate [Resolvido]

Boa tarde,

Gostaria de saber como faço essa simples consulta no banco de dados :

SELECT 
  product.name, 
  product.id
FROM 
  public.product,
  public.category
WHERE 
  category.description like '%teste%';

Tenho a seguintes classes mapeadas:

@Entity
public class Product implements Serializable {	
	private static final long serialVersionUID = 1L;
	private Long id;
	private String name;
	private Category category;
	private File photo;
	
	@Id
	@SequenceGenerator(name="sequence_product", sequenceName="sequence_product", initialValue=1)
	@GeneratedValue(strategy=GenerationType.AUTO, generator="sequence_product")
	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(length=60, nullable=false)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToOne(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	public Category getCategory() {
		return category;
	}
	
	public void setCategory(Category category) {
		this.category = category;
	}
	
	public File getPhoto() {
		return photo;
	}
		
	public void setPhoto(File photo) {
		this.photo = photo;
	}
	
}

e pensei que da seguinte forma conseguiria:

public List<Product> listAllByCategoryDescription(String description){
		return this.getSession().createCriteria(Product.class)
					.add(Restrictions.like("category.description", description))
					.list();
}

Mais o hibernate lança a seguinte steak trace:


org.hibernate.QueryException: could not resolve property: product of: br.com.bfree.model.Product
	at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
	at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
	at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1482)
	at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:62)
	at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1457)
	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:483)
	at org.hibernate.loader.criteria.CriteriaQueryTranslator.findColumns(CriteriaQueryTranslator.java:498)
	at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:68)
	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:380)
	at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:113)
	at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
	at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1697)
	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
	at br.com.bfree.dao.ProductDao.listAllByCategoryDescription(ProductDao.java:35)
	at br.com.bfree.dao.ProductDaoTest.shouldListAllByCategoryDescription(ProductDaoTest.java:127)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Alguém poderia me dizer como faço essa consulta?

cara,

faz o seguinte

select p from Product p inner join fetch p.category c where c.description like '%teste%'

t+

[quote=alissonvla]cara,

faz o seguinte

select p from Product p inner join fetch p.category c where c.description like '%teste%'

t+[/quote]

Sem usar HQL há solução?

testa ai

public List<Product> listAllByCategoryDescription(String description){
		return this.getSession().createCriteria(Product.class)
                                        .setFetchMode("category", FetchMode.EAGER)
					.add(Restrictions.like("category.description", description))
					.list();
}

Faz assim:

public List&lt;Product&gt; listAllByCategoryDescription(String description){ return this.getSession().createCriteria(Product.class).createAlias("category", "c").add(Restrictions.like("c.description", description)).list(); }

[quote=alissonvla]testa ai

public List<Product> listAllByCategoryDescription(String description){
		return this.getSession().createCriteria(Product.class)
                                        .setFetchMode("category", FetchMode.EAGER)
					.add(Restrictions.like("category.description", description))
					.list();
}

[/quote]

alissonv

Não funcionou cara continua com o mesmo erro.

[quote=romarcio]Faz assim:

public List&lt;Product&gt; listAllByCategoryDescription(String description){ return this.getSession().createCriteria(Product.class).createAlias("category", "c").add(Restrictions.like("c.description", description)).list(); }
[/quote]

Bah tchê, Funcionou direitinho.
Obrigado pela ajuda guri!

:thumbup: