Ok, sorry for asking this question but I never did a bidirectional many-to-one, and the only thing I know is I need put the inverse on the many =p
I already made it work with a unidirectional and I discovered after the project already started I needed it bidirectional, I have a scheme on visio of what is need, and I am here asking for a help making it works.
Here is the image
and the code I have so far
Type Class
Code:
public class Type{
private Long ID;
private String TYPE_NAME;
private String TYPE_COLOR;
private String TYPE_PICTURE;
private boolean TYPE_VISIBLE;
private Set news = new HashSet();
(Sets and Gets)(...)
Type Hibernate XML
Code:
<hibernate-mapping>
<class name="projects.news.Type" table="TB_NEWS_TYPE">
<id name="ID" column="ID">
<generator class="native"/>
</id>
<property name="TYPE_NAME" not-null="true" length="255" unique="true"/>
<property name="TYPE_COLOR" not-null="true" length="255"/>
<property name="TYPE_PICTURE" not-null="true" length="255"/>
<property name="TYPE_VISIBLE" not-null="true" type="java.lang.Boolean"/>
<set name="news" table="TB_NEWS">
<key column="NEWS_TYPE"/>
<one-to-many class="projects.news.News"/>
</set>
</class>
</hibernate-mapping>
News Class
Code:
public class News{
private Long ID;
private Long NEWS_TYPE;
private String NEWS_TITLE;
private String NEWS_DESC;
private Date NEWS_DATE;
private String NEWS_AUTHOR;
private Long PROJECT_ID;
private Set comments = new HashSet();
(Sets and Gets)(...)
News Hibernate XML
Code:
<hibernate-mapping>
<class name="projects.news.News" table="TB_NEWS">
<id name="ID" column="ID">
<generator class="native"/>
</id>
<property name="NEWS_TYPE"/>
<property name="NEWS_TITLE" not-null="true" length="255"/>
<property name="NEWS_DESC" not-null="true" length="65535"/>
<property name="NEWS_DATE" not-null="true" type="timestamp"/>
<property name="NEWS_AUTHOR" length="255"/>
<property name="PROJECT_ID" not-null="true"/>
<set name="comments" table="TB_NEWS_COMMENTS">
<key column="NEWS_ID"/>
<one-to-many class="projects.news.NewsComments"/>
</set>
</class>
</hibernate-mapping>
What I need change to make it works bidirectional with the type table
Thank you