JPA

orderbyとMap with one-to-manyでの確認

指定はアノテーションのみで簡単。 @OneToMany(targetEntity=Employee.class, mappedBy="department") @OrderBy("name DESC") private List enployees; ↑ちなみに大文字(DESC)じゃないとソートされなかった。SpecにはASC,DESCで表記されているから、きっとそ…

OneToManyで確認

Department(1..*)Employeeを見た際に、以下のように宣言。 @OneToMany(targetEntity=Employee.class, mappedBy="department") private List enployees; で、以下のように実行すると部課コードに該当するEmployeeを検索し、名前を出力する。 Department dep =…

PrimaryKeyJoinColumn

ParkingテーブルのIDがEmployeeテーブルのIDに対してFK張っている場合(かつ双方向)を確認 Employeeクラスでこんな宣言。 @OneToOne @PrimaryKeyJoinColumn private Employee employee; Employeeクラスはこんな宣言。 @OneToOne(mappedBy="employee") privat…

シーケンス....

Employeeのidに @SequenceGenerator(name="employee_gen", sequenceName="empseq") @GeneratedValue(generator="employee_gen") @Id として、実行!!! Exception in thread "main" javax.persistence.PersistenceException: Exception [TOPLINK-7144] (Ora…

ManyToOneで検索して内容を確認する。この前のEmployeeに ↓を追加 @ManyToOne @JoinColumn(name="DEPT_ID") private Department department; EmployeeテーブルにDEPT_IDを追加し、FKを設ける。 そのDEPT_IDに対応する新しくDepartmentのテーブルとクラスを作…

HelloWorld程度にサンプルとして、軽く動かす。 先日ダウンロードしたglassfishからentity-persistenceとpersistence-apiの内容をEclipse上にプロジェクトとして展開 jta.jarにclasspathを通す。 antlrは今は無視。 作ったのはコレ。まずはエンティティモデ…

GettingReady

JPAの修行をするべく準備開始。関連ダウンロード hibernate:http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=156160, http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=139933 glassfish:https://glassf…