Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA mapping question

 
Venkata Raaman
Ranch Hand
Posts: 46
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my jsf page(xhtml) i have a dropdown field called Student(persists to Student TABLE)
which has 3 options whose values come from an other table(studenttype).i.e Bachelor, Masters, Ph.D

There is NO pk OR OTHER Relation between those 2 tables.

Can I write my JPA (Student.java) like this:

@Entity
@Table(name="student", schema="student")

@SecondaryTable(name="studenttype")
public class Student implements Serializable{

//Student table PK
@Id
@Column(name="STUDENT_ID")
private Long studentId;

@Column(name="STUDENTTYPE", table="studenttype")
private String studentType;
//getters n setters
}

My Question is how can write JPA code to take values from a table(like some codetable)
where there is no relation and put them into another table(major table).
finally a studenttype option has to be entered as String into student table.
Hope I am clear.
Thanks in adv
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could order your list using a Comparator or Comparable.

Also you can use a namedQuery to order your list when you get your data from the database.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could create an Entity for StudentType and map it to the studenttype table. You can then query this table to populate your drop downs.

Then either just use the String value from the drop down, or have Student have a StudentType instead of a String, and make the String value the Id of StudentType.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic