[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: hbm.xml to javax.persistence annotations problems

mpurdy1973 do-not-reply at jboss.com
Thu Jul 16 22:46:06 EDT 2009


i figured it out.  the problem it was my first time with JPA annotations, now it is clear.

i used JoinTable annotation, which is used in a many to many relationship, which cause hibernate to create a link table.

once i switch it back to JoinColumn, it worked the same:

code from User

  |    @OneToMany
  |    (
  |       mappedBy     = "id",
  |       targetEntity = TrainingRequest.class, 
  |       fetch        = FetchType.EAGER, 
  |       cascade      = CascadeType.ALL
  |    )
  |    private Set<TrainingRequest> trainingRequests;
  | 

code from TrainingRequest

  |    @ManyToOne()
  |    @JoinColumn
  |    (
  |       name      = "user_id",
  |       nullable  = false, 
  |       updatable = false
  |    )
  |    private User user;
  | 

db output from mysql

  | mysql> show tables;
  | +------------------+
  | | Tables_in_test   |
  | +------------------+
  | | trainingrequests | 
  | | users            | 
  | +------------------+
  | 2 rows in set (0.00 sec)
  | 
  | mysql> desc users;
  | +----------+--------------+------+-----+---------+----------------+
  | | Field    | Type         | Null | Key | Default | Extra          |
  | +----------+--------------+------+-----+---------+----------------+
  | | user_id  | bigint(20)   | NO   | PRI | NULL    | auto_increment | 
  | | password | varchar(255) | YES  |     | NULL    |                | 
  | | username | varchar(255) | YES  |     | NULL    |                | 
  | +----------+--------------+------+-----+---------+----------------+
  | 3 rows in set (0.01 sec)
  | 
  | mysql> desc trainingrequests;
  | +--------------------+--------------+------+-----+---------+----------------+
  | | Field              | Type         | Null | Key | Default | Extra          |
  | +--------------------+--------------+------+-----+---------+----------------+
  | | trainingrequest_id | bigint(20)   | NO   | PRI | NULL    | auto_increment | 
  | | cost               | double       | YES  |     | NULL    |                | 
  | | subject            | varchar(255) | YES  |     | NULL    |                | 
  | | summary            | varchar(255) | YES  |     | NULL    |                | 
  | | user_id            | bigint(20)   | NO   | MUL | NULL    |                | 
  | +--------------------+--------------+------+-----+---------+----------------+
  | 5 rows in set (0.00 sec)
  | 



View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4244203#4244203

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4244203



More information about the jboss-user mailing list