• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot deploy the student, course and semester example in the spec

 
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am trying to implement example 3 of @MapKeyJoinColumn in the spec:





CREATE TABLE  STUDENT (ID INTEGER AUTO_INCREMENT,   PRIMARY KEY (ID));
CREATE TABLE COURSE (ID INTEGER AUTO_INCREMENT, PRIMARY KEY (ID));
CREATE TABLE SEMESTER(ID INTEGER AUTO_INCREMENT, PRIMARY KEY(ID));
CREATE TABLE ENROLLMENTS (STUDENT INTEGER NOT NULL, SEMESTER INTEGER NOT NULL, COURSE INTEGER NOT NULL,   PRIMARY KEY (STUDENT, SEMESTER,COURSE));
ALTER TABLE ENROLLMENTS ADD CONSTRAINT STUREF FOREIGN KEY (STUDENT) REFERENCES STUDENT (ID);
ALTER TABLE ENROLLMENTS ADD CONSTRAINT SEMPREF FOREIGN KEY (SEMESTER) REFERENCES SEMESTER (ID);
ALTER TABLE ENROLLMENTS ADD CONSTRAINT COUREF FOREIGN KEY (COURSE) REFERENCES COURSE(ID);


When I deploy it, I get this error message:


cannot Deploy Courses
deploy is failing=Error occurred during deployment: Exception while deploying the app [Courses] : Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Deployment of PersistenceUnit [StudentService] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [SEMESTER] is not present in this descriptor.
Descriptor: RelationalDescriptor(com.examples.model.Course --> [DatabaseTable(COURSE)])


I am using Eclipse with Glassfish 4.1. I hope that is not a bug of EclipseLink.
Please help.
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I even add this to the Semester Entity class:

But that does not help.
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to add a many-to-many relationship to student and courses:




Now, it can be deployed.
Let me do more work on it tomorrow.
By the way, why the many-to-many relationship is important for the student and course?
I thought the many-to-many relationship is just for student and semester.
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you creating the tables yourself? Or do you let the persistence provider create them for you?

This is not the primary key that I would expect from that mapping:

PRIMARY KEY (STUDENT, SEMESTER,COURSE);

 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created those tables myself using the SQL statements first before I create the entity classes.
I guess the composite primary key is (student, semester , course) instead of (student, semester) or (student, course).

If I use two columns as the composite key, this key may not be unique. The enrollments join table will be like this for example:
Student   Semester   Course
----------------------------------
1              Spring        JPA
1              Spring        EJB
1              Winter        Servlet
1              Winter        JSF
1              Fall            JSF
1              Summer     JSF

I cannot pick (student, semester) or (student, course) as the composite key because of these reasons:
- a student may enroll in more than one course in one semester or
- a student may repeat the same course in different semesters.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just let the tables be created by the persistence provider and see how it is done.

Hint: use these properties in your persistence.xml:
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Frits.
Thanks for your suggestion.
I use the JPA provider to create the tables, course, student, semester and enrollment.
In the enrollment table, the three columns : student, course and semester are a composite of primary keys.
 
Himai Minh
Bartender
Posts: 2416
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me add one more comment on my previous post:


If I use two columns as the composite key, this key may not be unique. The enrollments join table will be like this for example:
Student   Semester   Course
----------------------------------
1              Spring        JPA
1              Spring        EJB
1              Winter        Servlet
1              Winter        JSF
1              Fall            JSF
1              Summer     JSF



Course is a key of a hash map and it must be unique. So, there is no possibility that student 1 can take JSF course more than once.
So, I think the composite primary key should be student and course.
But when the join table is generated, the composite primary key is student, course and semester.
 
reply
    Bookmark Topic Watch Topic
  • New Topic