0

一致する提案の質問がたくさんありますが、どの提案も私の質問に答えていないようです。私はHibernateの初心者で、注釈を始めたばかりです。XML 構成でやや快適。「休止状態の活用」を行っていて、注釈サンプルを試していました。そして、これを実行しようとすると、この例外が発生します。私のコードはここにあります

hibernate.cfg.xml

    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

    <!-- Generated by MyEclipse Hibernate Tools.                   -->
    <hibernate-configuration>

` <session-factory>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <!--  MySQL connection     -->
      <property name="connection.url">jdbc:mysql://localhost:3306/HibernateTest</property>
      <property name="connection.username">root</property>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.password">root</property>`

    <property name="current_session_context_class">thread</property>
    <!-- this will show us all sql statements -->

    <property name="connection.pool_size">1</property>
    <property name="hibernate.show_sql">false</property>
    <!-- this will create the database tables for us --><!--
    <property name="hibernate.hbm2ddl.auto">create</property>
    --><!--<property name="jdbc.batch_size">0</property>
    <mapping resource="com/home/hibernate/data/Track.hbm.xml" />
    <mapping resource="com/home/hibernate/data/Artist.hbm.xml" />
    <mapping resource="com/home/hibernate/data/Album.hbm.xml" />
  -->
    <mapping class="com.home.hibernate.bean.Track"/>
    <mapping class="com.home.hibernate.bean.Album"/>
    <mapping class="com.home.hibernate.bean.AlbumTrack"/>
    <mapping class="com.home.hibernate.bean.Artist"/> 
  </session-factory>

</hibernate-configuration>

Track.java

    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;

    import org.hibernate.annotations.CollectionOfElements;
    import org.hibernate.annotations.Index;

    @Entity
    @Table(name="TRACK")
    @NamedQueries({
        @NamedQuery(name="queryTest.tracksNoLongerThan",
                query="from Track as track where track.playTime <= :length")
    })
    public class Track  implements java.io.Serializable {

    @Id
    @Column(name="TRACK_ID")
    @GeneratedValue(strategy=GenerationType.AUTO)
     private int id;

    @Column(name="TITLE",nullable=false)
    @Index(name="TRACK_TITLE",columnNames={"TITLE"})
     private String title;

    @Column(nullable=false)
     private String filePath;

    @Temporal(TemporalType.TIME)
     private Date playTime;

    @Temporal(TemporalType.DATE)
     private Date added;

    @ManyToMany
    @JoinTable(name="TRACK_ARTISTS",
            joinColumns={@JoinColumn(name="ARTIST_ID")},
            inverseJoinColumns={@JoinColumn(name="TRACK_ID")})
     private Set<Artist> artists = new HashSet<Artist>(0);
     /**
      * Media on which track was obtained
     */
    @Enumerated(EnumType.STRING)
     private SourceMedia sourceMedia;

     @CollectionOfElements
     @JoinTable(name="TRACK_COMMENTS",
            joinColumns={@JoinColumn(name="TRACK_ID")})
    @Column(name="COMMENT")
     private Set<String> comments = new HashSet<String>(0);
     /**
      * How loud to play
     */
     @Embedded
     @AttributeOverrides({
         @AttributeOverride(name="left", column=@Column(name="VOL_LEFT")),
         @AttributeOverride(name="right", column=@Column(name="VOL_RIGHT"))
     })
     private StereoVolume volume;

    public Track() {
    }


    public Track(String title, String filePath) {
        this.title = title;
        this.filePath = filePath;
    }
    public Track(String title, String filePath, Date playTime, Date added, Set<Artist> artists, SourceMedia sourceMedia, Set<String> comments, StereoVolume volume) {
       this.title = title;
       this.filePath = filePath;
       this.playTime = playTime;
       this.added = added;
       this.artists = artists;
       this.sourceMedia = sourceMedia;
       this.comments = comments;
       this.volume = volume;
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }
    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    public String getFilePath() {
        return this.filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }
    public Date getPlayTime() {
        return this.playTime;
    }

    public void setPlayTime(Date playTime) {
        this.playTime = playTime;
    }
    public Date getAdded() {
        return this.added;
    }

    public void setAdded(Date added) {
        this.added = added;
    }
    public Set<Artist> getArtists() {
        return this.artists;
    }

    public void setArtists(Set<Artist> artists) {
        this.artists = artists;
    }
    /**       
     *      * Media on which track was obtained
     */
    public SourceMedia getSourceMedia() {
        return this.sourceMedia;
    }

    public void setSourceMedia(SourceMedia sourceMedia) {
        this.sourceMedia = sourceMedia;
    }
    public Set<String> getComments() {
        return this.comments;
    }

    public void setComments(Set<String> comments) {
        this.comments = comments;
    }
    /**       
     *      * How loud to play
     */
    public StereoVolume getVolume() {
        return this.volume;
    }

    public void setVolume(StereoVolume volume) {
        this.volume = volume;
    }

    /**
     * toString
     * @return String
     */
     public String toString() {
      StringBuffer buffer = new StringBuffer();

      buffer.append(getClass().getName()).append("@").append(Integer.toHexString(hashCode())).append(" [");
      buffer.append("title").append("='").append(getTitle()).append("' ");          
      buffer.append("sourceMedia").append("='").append(getSourceMedia()).append("' ");          
      buffer.append("volume").append("='").append(getVolume()).append("' ");            
      buffer.append("]");

      return buffer.toString();
     }



}

Build.xml

    <artifact:dependencies pathId="dependency.classpath">
        <dependency groupId="mysql" artifactId="mysql-connector-java"
            version="5.0.5" />

        <dependency groupId="org.hibernate" artifactId="hibernate"
            version="3.2.5.ga">
            <exclusion groupId="javax.transaction" artifactId="jta"></exclusion>
        </dependency>

        <dependency groupId="org.hibernate" artifactId="hibernate-annotations"
                version="3.3.0.ga">
        </dependency>

        <dependency groupId="org.hibernate" artifactId="hibernate-commons-annotations"
                version="3.3.0.ga">
        </dependency>

        <dependency groupId="org.hibernate" artifactId="hibernate-tools"
            version="3.2.0.beta9a" />


        <dependency groupId="org.apache.geronimo.specs" artifactId="geronimo-jta_1.1_spec"
            version="1.1" />
        <dependency groupId="log4j" artifactId="log4j" version="1.2.14" />

    </artifact:dependencies>

これは、アプリケーションで使用したすべての依存関係です

そして、私のエラートレースは

    BUILD FAILED
    D:\Hibernate-SelfStudy\Workspace\HibernateTutorial\build.xml:19: org.hibernate.MappingException: Could not determine type for: java.util.Set, for colu
    mns: [org.hibernate.mapping.Column(comments)]
            at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
            at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:138)
            at org.hibernate.mapping.Column.getSqlType(Column.java:182)
            at org.hibernate.mapping.Table.sqlCreateString(Table.java:394)
            at org.hibernate.cfg.Configuration.generateSchemaCreationScript(Configuration.java:848)
            at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:94)
            at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61)
            at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
            at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:183)
            at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
            at org.apache.tools.ant.Task.perform(Task.java:348)
            at org.apache.tools.ant.Target.execute(Target.java:392)
            at org.apache.tools.ant.Target.performTasks(Target.java:413)
            at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
            at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
            at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
            at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
            at org.apache.tools.ant.Main.runBuild(Main.java:811)
            at org.apache.tools.ant.Main.startAnt(Main.java:217)
            at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
            at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)

    Total time: 3 seconds

誰でもこれで私を助けてくれますか

よろしくお願いします

4

2 に答える 2

0

質問でごめんなさい。エラーは他のクラスでスローされました。コメントコレクションの注釈が間違って付けられた場合。

于 2013-01-07T00:29:38.447 に答える
0

@ElementCollection の代わりに使用し@CollectionOfElementsます。廃止されました。

それが役に立ったことを願っています:)

于 2013-01-03T18:45:40.913 に答える