remix wrote:
hi everybody,
i have read the documentation and still need help.
I have 4 tables THEME, FEED_THEME, FEED, NEWS.
theme and feed are many-to-many.
feed and news are one-to-many.
i have this query working (last news ordered for a given theme):
Code:
SELECT n . *
FROM `feed_theme` ft, `feed` f, `news` n
WHERE ft.id_theme =3
AND f.id_feed = ft.id_feed
AND n.id_feed = f.id_feed
ORDER BY n.founddate DESC , n.newsdate
LIMIT 20
but i don't know how to get this query working with hibernate.
This query return a list of object News.thanks for your help
another question:
do you think it's possible to do that with hibernate?more informations: a theme(wich is a category) has many feed, a feed has many news.
here are my hbm.xml file:
theme.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.woox.givemefive.model">
<class name="Theme" table="theme">
<id name="id_theme" column="id_theme">
<generator class="increment" />
</id>
<property name="title" column="title" />
<property name="description" column="description" />
<set name="feeds" table="feed_theme">
<key column="id_theme"/>
<many-to-many column="id_feed" class="Feed"/>
</set>
</class>
</hibernate-mapping>
feed.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.woox.givemefive.model">
<class name="Feed" table="feed">
<id name="id_feed" column="id_feed" type="java.lang.Long">
<generator class="increment"/>
</id>
<property name="url" column="url" type="java.lang.String" />
<property name="name" column="name" type="java.lang.String" />
<property name="title" column="title" type="java.lang.String" />
<property name="description" column="description" type="java.lang.String" />
<property name="siteurl" column="siteurl" type="java.lang.String" />
<property name="isactive" column="isactive" type="java.lang.Boolean" />
<property name="lastupdate" column="lastupdate" type="timestamp" />
<set name="newsList">
<key column="id_feed" />
<one-to-many class="News"/>
</set>
<set name="themes" table="feed_theme" inverse="true">
<key column="id_feed"/>
<many-to-many column="id_theme" class="Theme"/>
</set>
</class>
</hibernate-mapping>
and news.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.woox.givemefive.model">
<class name="News" table="news">
<id name="id_news" column="id_news">
<generator class="increment" />
</id>
<property name="id_feed" column="id_feed" />
<property name="title" column="title" />
<property name="description" column="description" />
<property name="link" column="link" />
<property name="author" column="author" />
<property name="newsdate" column="newsdate" type="timestamp" />
<property name="founddate" column="founddate" type="timestamp" />
<many-to-one name="feed" class="Feed" insert="false" update="false" column="id_feed" />
</class>
</hibernate-mapping>