成功捷徑,貴在堅(jiān)持
          人為善,福雖未至禍已遠(yuǎn)離; 人為惡,禍雖未至福已遠(yuǎn)離

          @SuppressWarnings("serial")
          @Entity
          @Table(name = "BOOK")
          @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
          public class Book implements Serializable{

          ?private static final long serialVersionUID = -2700610405985954588L;
          ?
          ?private int oid;
          ?
          ?private String name;
          ?
          ?private String description;
          ?
          ?private Date publish;
          ?
          ?private Collection<Author> authors;

          ?@Id
          ?@GeneratedValue(strategy=GenerationType.SEQUENCE)
          ?public int getOid() {
          ??return oid;
          ?}

          ?public void setOid(int oid) {
          ??this.oid = oid;
          ?}

          ?public String getName() {
          ??return name;
          ?}

          ?public void setName(String name) {
          ??this.name = name;
          ?}

          ?public String getDescription() {
          ??return description;
          ?}

          ?public void setDescription(String description) {
          ??this.description = description;
          ?}

          ?@Temporal(value=TemporalType.TIMESTAMP)
          ?public Date getPublish() {
          ??return publish;
          ?}

          ?public void setPublish(Date publish) {
          ??this.publish = publish;
          ?}


          ?@ManyToMany(
          ???targetEntity=com.e104cn.pda.data.anno.Author.class,
          ???cascade ={CascadeType.PERSIST,CascadeType.MERGE},
          ??????????? fetch=FetchType.LAZY
          ?)
          ?@JoinTable(
          ???????? name = "book_author",
          ???????? joinColumns ={@JoinColumn(name="book_id")},
          ???????? inverseJoinColumns ={@JoinColumn(name= "author_id")}
          ?? )
          ?public Collection<Author> getAuthors() {
          ??return authors;
          ?}
          ?
          ?public void addAuthor(Author author){
          ??if(author == null){
          ???authors = new ArrayList<Author>();
          ??}
          ??if(!authors.contains(author)){
          ???authors.add(author);
          ??}
          ?}

          ?public void setAuthors(Collection<Author> authors) {
          ??this.authors = authors;
          ?}
          ?
          }

          /**@SuppressWarnings("serial")
          @Entity
          @Table(name = "AUTHOR")
          @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)*/

          public class Author implements Serializable{

          ?private static final long serialVersionUID = 7131973910486229579L;
          ?
          ?private int id;
          ?
          ?private String firstName;
          ?
          ?private String lastName;
          ?
          ?private boolean male;
          ?
          ?private Date birthday;
          ?
          ?@Transient
          ?private Collection<Book> books ;

          ?@Id
          ?@GeneratedValue(strategy=GenerationType.SEQUENCE)
          ?public int getId() {
          ??return id;
          ?}

          ?public void setId(int oid) {
          ??this.id = oid;
          ?}

          ?public String getFirstName() {
          ??return firstName;
          ?}

          ?public void setFirstName(String firstName) {
          ??this.firstName = firstName;
          ?}

          ?public String getLastName() {
          ??return lastName;
          ?}

          ?public void setLastName(String lastName) {
          ??this.lastName = lastName;
          ?}

          ?public boolean isMale() {
          ??return male;
          ?}

          ?public void setMale(boolean male) {
          ??this.male = male;
          ?}

          ?@Temporal(value=TemporalType.TIMESTAMP)
          ?public Date getBirthday() {
          ??return birthday;
          ?}

          ?public void setBirthday(Date birthday) {
          ??this.birthday = birthday;
          ?}

          ?@ManyToMany(mappedBy="authors",
          ??cascade={CascadeType.PERSIST,CascadeType.ALL}
          ?)
          ?public Collection<Book> getBooks() {
          ??return books;
          ?}

          ?public void addBook(Book book){
          ??if(books == null){
          ???books = new ArrayList<Book>();
          ??}
          ??if(!books.contains(book)){
          ???books.add(book);
          ??}
          ?}
          ?
          ?public void setBooks(Collection<Book> books) {
          ??this.books = books;
          ?}
          ?
          }
          1、去掉藍(lán)色注釋的部分即可解決錯(cuò)誤.
          2、?注:@ManyToMany(mappedBy="authors",屬性一定要和book中的authors一致。

          posted on 2008-05-20 08:54 選寶網(wǎng)an9 閱讀(6677) 評(píng)論(0)  編輯  收藏 所屬分類: Java Exception&Error
          主站蜘蛛池模板: 青铜峡市| 会泽县| 清水河县| 普定县| 长沙市| 巴林右旗| 湟中县| 徐州市| 荥经县| 调兵山市| 丽江市| 武川县| 偃师市| 夏邑县| 虞城县| 阳春市| 德保县| 广东省| 荔浦县| 郑州市| 鱼台县| 鹤峰县| 泰安市| 永新县| 乌拉特后旗| 南丰县| 霍林郭勒市| 大田县| 进贤县| 宁安市| 高邑县| 河源市| 乌拉特中旗| 鹤岗市| 徐闻县| 荃湾区| 泊头市| 富源县| 广西| 全南县| 长武县|