I have the following code:
[code]
@Entity
@Table(name = "categories_tbl")
@NamedQueries( {
@NamedQuery(name = "Categories.findByParent", query = "SELECT c FROM Categories c WHERE c.superCat.categoryid = :categoryid")
})
public class Categories implements Serializable {
@Id
@GeneratedValue(generator="category_gen")
@TableGenerator(name="category_gen", table="id_gen",
pkColumnName="gen_name", valueColumnName="gen_val",
pkColumnValue="category_seq")
@Column(name = "Category_id", nullable = false)
private Integer categoryid;
@Column(name = "Category_name")
private String categoryname;
@Lob
@Column(name = "Category_Description")
private String categoryDescription;
@Column(name = "Avalability")
private Character avalability;
@Column(name = "View_stats", nullable = false)
private int viewstats;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "categories")
private Collection<ProductsToCategories> productsToCategoriesCollection;
@OneToMany(mappedBy = "superCat")
private Collection<Categories> categoriesCollection;
@JoinColumn(name = "SuperCat", referencedColumnName = "Category_id")
@ManyToOne
private Categories superCat;
[/code]
where superCat is the super category of a category.
when I try to search for non-null super category, say every category whose super category is 1, everything is ok. but when I try to search for null super category, categories which does not belong to any category, by setting categoryid in the namedquery to null, it returns 0 even though they are in the database.
Any idea? Thank you
[Message sent by forum member 'eviljanca' (eviljanca)]
http://forums.java.net/jive/thread.jspa?messageID=237502