-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Need help, can't find info on this ANYWHERE
PostPosted: Fri May 12, 2006 3:57 pm 
Newbie

Joined: Fri May 12, 2006 3:39 pm
Posts: 13
Hey everyone,

I'm new to hibernate, so forgive me if this question is 'elementary', but I have been searching for a while and have found nothing, so I hope that someone here can help.

What I have is 2 classes which I am trying to populate from a single database. I have 1 parent 'news' class with 2 child classes 'dailyNews' and 'generalNews'. There is also an 'affiliateNews' class. Each affiliateNews class has exactely 1 generalNews object and can have multiple dailyNews objects. Each news object relates to only 1 affiliate.

The database structure we have been working with contains all of the data in 1 table. There is a 'newsType' field which indicates whether the news is general or daily. There is also a field called 'affiliateID' which identifies the affiliateNews object.

We were trying to have hibernate populate the affiliateNews object which contains 1 member variable of type generalNews called 'generalNews' and 1 member variable which is a sorted set called 'dailyNews'. We want to retrieve all of the dailyNews objects as a sorted set, and set them in 'dailyNews' and retrieve the sole generalNews object and set it in 'generalNews'.

Using the below mapping files, we can get this to compile and run, but the sortedset in the AffiliateMapping object retrieves both the 'GeneralNews' and the 'DailyNews' objects. We have been unsuccessful in mapping the 'GeneralNews' object to its member variable.


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">
<!-- Auto-generated mapping file from the hibernate.org cfg2hbm engine -->
<class name="com.adsmack.smacklet.news.domain.AffiliateNews" table="news">
<id name="affiliateID" type="integer">
<column name="id" />
<generator class="increment" />
</id>

<set name="dailyNews" table="news" sort="natural">
<key column="affiliateID" not-null="true" />
<one-to-many class="com.adsmack.smacklet.news.domain.AffiliateDailyNews" />
</set>

</class>
</hibernate-mapping>

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false">
<!-- Auto-generated mapping file from the hibernate.org cfg2hbm engine -->
<class name="com.adsmack.smacklet.news.domain.News" table="news" >
<id name="id" type="integer">
<column name="ID" />
<generator class="increment" />
</id>
<discriminator column="newstype" />
<property name="article" type="string">
<column name="article" />
</property>

<subclass name="com.adsmack.smacklet.news.domain.AffiliateDailyNews"
discriminator-value="DAILYNEWS" >
<property name="dateSubmitted" type="timestamp">
<column name="dateSubmitted" />
</property>
<property name="title" type="string">
<column name="title" />
</property>
<property name="articleLink" type="string">
<column name="articlelink" />
</property>
<property name="linkText" type="string">
<column name="linktext" />
</property>
</subclass>

<subclass name="com.adsmack.smacklet.news.domain.AffiliateGeneralNews"
discriminator-value="GENERALNEWS" />
</class>
</hibernate-mapping>

DB Schema ....

DROP TABLE IF EXISTS `news`;
CREATE TABLE `news` (
`id` int(10) unsigned NOT NULL auto_increment,
`article` text NOT NULL,
`datesubmitted` datetime NOT NULL default '0000-00-00 00:00:00',
`title` varchar(100) NOT NULL default '',
`articlelink` varchar(100) default NULL,
`linktext` varchar(50) default NULL,
`newstype` varchar(45) NOT NULL default '',
`affiliateid` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `FK_news_1` (`affiliateid`),
CONSTRAINT `FK_news_1` FOREIGN KEY (`affiliateid`) REFERENCES `affiliatenews` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Thanks you


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.