I'm trying to use JBOSS IDE for Eclipse but I'm having trouble using an automatic generated id populated from a Oracle sequence previously created in the database. I guess there is some aditional configuration that I need to do in my application but I don't know what it is.
In the persistence XML I have:
At the entity bean I have:
I'm getting the error "java.sql.SQLException: ORA-02289: sequence does not exist".
Actually, keep the AUTO in there, but make sure Oracle has a Hibernate Sequence tabled, named "hibernate_seq" or something along those lines. But if you have a hibernate sequence all tables will use that one sequence generator.
If you have a sequence table for each table, then you need another annotation that you put the name of the sequence table to use, but I forget the exact name of that Annotation.
I need an sequence for each table so I changed my code according to your information and worked with the sequence but now I'm getting an error with the foreign key. I have two entity beans Person and Address both of them with the key being generated by two different sequences: person_seq and address_seq. Person has an foreign key that references the field "id" of the Address table. In the Person ejb I have:
In the Address ejb I have:
Both tables are empty and I'm trying to add an register in the table Person and Address but I'm getting the following error:
ORA-02291: integrity constraint (ADM.FK_ADDRESS) violated - parent key not found
I'm getting some warnings when I start JBOSS:
"14:32:28,570 WARN [Ejb3Configuration] Persistence provider caller does not implements the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null."
"14:32:28,898 WARN [AnnotationBinder] Hibernate does not support SequenceGenerator.initialValue()"
Do you think these warns have to do with the error message?
I don't think addressId and id are the correct values to do for your join. What is the actual column name, and if it is not address_id, then you will need an @Column for the id attribute of the Address object, and probably the same for the Person object.
If you have an attribute called "id" and no @Column, Hibernate will assume the primary key field is the name of the class plus an underscore plus "id" so for a Person object with an "id" attribute marked at the @Id, then the primary field name in the database should be "person_id"
Joined: May 08, 2007
I added the Column(name =�id�) annotation before the getId() method of Person and Address ejb but I�m getting the same error message about the foreign key violation. My Oracle tables have the following fields:
Name Type Nullable Default -------- ------------- -------- ------- ID NUMBER NAME VARCHAR2(80) Y ADDRESSID NUMBER(10) Y EMAIL VARCHAR2(80) Y PASSWORD VARCHAR2(64) Y GENDER VARCHAR2(20) Y NULL ...and some more fields
The field ID is the primary key and ADDRESSID is a foreign key.
Name Type Nullable Default -------- ------------- -------- ------- ID NUMBER(10) LINE1 VARCHAR2(255) Y NULL COUNTRY VARCHAR2(150) Y NULL POSTCODE VARCHAR2(50) Y NULL
The field ID is the primary key
I have two entity beans called Person and Address. The data of the tables is entered using the register.jsp page that uses the Register.java class to save the contents to the tables as showed below:
The EntityFacadeBean uses a EntityManager to save the records in the table and the annotations in the beans are:
The entity manager is responsible for recording the informations in the database, then shouldn�t it be recording the registers in the correct order: the Address first and the Person data after that?
I don't see where you add an Address record. So basically what I see is you create a Person object, with no Address object in it, and you go to insert the person into the database, but there is no corresponding address record. Since addressid is a FK it must have a value. In your model Address is the parent table of person, so there would have to be an Address record inserted before you can insert a Person record. (which normally it is the other way around)
Joined: May 08, 2007
I have a JSP page that receives the data entered by the user. This page uses JSF.
The JSF configuration is:
So when the user enters the data in the JSP/JSF page and press submit the class Register.java is called with the Person ejb data filled, is that correct? As the Person ejb has the methods getAddress and setAddress, shouldn�t the entity manager create the records in the table Address and in the table Person?
OK, so if set a break point just before you call persist or save method, does the Person object have an Address object, or actually, in your case the Address object have a Person?
Joined: May 08, 2007
Sorry the late reply but I was busy with other activities. I just discovered why my code wasn't working. I had created an Oracle before insert trigger for Person and Address table that used the sequences to insert the primary key value in the tables. I didn't realize that JBOSS invokes the sequences to generate the primary key itself.