Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat does the Set type in a Entry
    text
    copied!<p>I have two tables in db,and one owns a foreign key from another,the fllowing is the schema:</p> <p>//table featureInfo</p> <pre><code>SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for featureinfo -- ---------------------------- DROP TABLE IF EXISTS `featureinfo`; CREATE TABLE `featureinfo` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `globalId` int(11) NOT NULL DEFAULT '0', `name` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`Id`), KEY `globalId` (`globalId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; </code></pre> <p>//another table featurefix</p> <pre><code>SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for featurefix -- ---------------------------- DROP TABLE IF EXISTS `featurefix`; CREATE TABLE `featurefix` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `globalId` int(11) NOT NULL DEFAULT '0', `modifyname` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`Id`), KEY `FK-Guid` (`globalId`), CONSTRAINT `FK-Guid` FOREIGN KEY (`globalId`) REFERENCES `featureinfo` (`globalId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; </code></pre> <p>Then I use the hbm2java to create the entry class:</p> <pre><code>public class Featureinfo implements java.io.Serializable { private Integer id; private int globalId; private String name; private Set featurefixes = new HashSet(0); public Featureinfo() {} } </code></pre> <p>Now I wonder why there is a set attribute in FeatureInfo?</p> <p>And the Featureinfo.hbm.xml:</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="com.pojo.Featureinfo" table="featureinfo" catalog="hibernateset"&gt; &lt;id name="id" type="java.lang.Integer"&gt; &lt;column name="Id" /&gt; &lt;generator class="identity" /&gt; &lt;/id&gt; &lt;property name="globalId" type="int"&gt; &lt;column name="globalId" not-null="true" /&gt; &lt;/property&gt; &lt;property name="name" type="string"&gt; &lt;column name="name" not-null="true" /&gt; &lt;/property&gt; &lt;set name="featurefixes" inverse="true"&gt; &lt;key&gt; &lt;column name="globalId" not-null="true" /&gt; &lt;/key&gt; &lt;one-to-many class="com.pojo.Featurefix" /&gt; &lt;/set&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>The set element are defines, why not use the "joined-subclass" instead?</p> <p>Also what is the difference between the "set/map/list/idbag" and "one-to-many/many-to-one" in the mapping xml file ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload