@NamedQueries({
        @NamedQuery(name="category.ByName", query="SELECT c from Category c where c.name = :name"),
        @NamedQuery(name="Category.getTopics", query="SELECT t FROM Topic t inner join Category c WHERE t.category.id = :categoryId")
})

public class Category extends GlobalTable implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name = "Category_SEQ", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "Category_SEQ")
    private int id;
    
    @Column(name = "name", nullable = false, length = 50)
    private String name;

    @Column(name = "description", nullable = false, columnDefinition = "TEXT")
    private String description;

    @ManyToOne
    private Forum forum;

    @OneToMany(targetEntity = Topic.class, mappedBy = "category")
    private Collection topics;
.........................


public class Topic extends GlobalTable implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @SequenceGenerator(name="Topic_SEQ", allocationSize=1)
    @GeneratedValue(strategy = GenerationType.AUTO, generator="Topic_SEQ")
    private int id;

    @Column(name="name",nullable=false, length=50)
    private String name;

    @Column(name="description",nullable=false,columnDefinition="TEXT")
    private String description;
    
    @Column(name="type",nullable=false)
    private int type;
    
    @ManyToOne
    private User user;

    @ManyToOne(targetEntity=Category.class)
    private Category category;

Add a code snippet to your website: www.paste.org