Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default How to Do One to Many Mapping in JPA For this scenario

    I have a class
    public class ExamCategoryDTO {
    @Id
    private Long id;
    @OneToMany(mappedBy = "examCategoryDTO", targetEntity = ExamNameDTO.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<ExamNameDTO> examNameList;
    }

    And another class
    public class ExamNameDTO {
    @Id
    private Long id;
    @Column(name="EXAM_CATEGORY_ID")
    private Long examCategoryId;
    @ManyToOne
    @JoinColumn(name = "EXAM_CATEGORY_ID")
    private ExamCategoryDTO examCategoryDTO;
    }

    If i do like this it gives error saying that EXAM_CATEGORY_ID is alearady mapped. I need to know the way to save ExamNameDTO without ExamCategoryDTO and i want to sent the Foreign key in ExamNameDTO manuaaly and Some times i want to save thru ExamCategoryDTO and in that case it will have ExamCategoryDTO as list. I want to do bothways. How can i do that. Please help

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Remove the
    Java Code:
    @Column(name="EXAM_CATEGORY_ID")
    private Long examCategoryId;
    part.

    The
    Java Code:
    @ManyToOne
    @JoinColumn(name = "EXAM_CATEGORY_ID")
    private ExamCategoryDTO examCategoryDTO;
    part already does that for you.

    Don't name your entities using DTO.

Similar Threads

  1. Can somebody please help me with a "tie" scenario...URGENT
    By university123 in forum New To Java
    Replies: 2
    Last Post: 10-25-2010, 12:58 PM
  2. Castor Mapping - Help
    By roddy in forum XML
    Replies: 1
    Last Post: 08-27-2009, 02:25 AM
  3. XML and Database Mapping in .NET
    By gilbertsavier in forum XML
    Replies: 0
    Last Post: 07-17-2009, 08:34 AM
  4. Servlet mapping
    By cozsmin in forum Java Servlet
    Replies: 1
    Last Post: 04-04-2009, 10:15 AM
  5. Scenario
    By ron87 in forum New To Java
    Replies: 1
    Last Post: 04-01-2009, 06:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •