Equivalent of @GeneratedValue in JBoss-4.0.5.GA
rajesh.r77 Oct 16, 2008 6:04 AMHi,
I am working on an application through which messages can be send to JMS Topic from browser and the MessageBean will store the received messages to a table called newsentity in postgresql database. The Entity Class name is NewsEntity. My application server is JBoss-4.0.5.GA and version is J2EE 1.4.
The table newsentity contains 3 fields - id, title and body. The id field is the PK and it's type is BIGSERIAL.
Since the id field will auto increment, I did not set any value to the id field while sending message to MessageBean.
InitialContext ctx = new InitialContext(); topic = (Topic) ctx.lookup("topic/mdb"); TopicConnectionFactory factory = (TopicConnectionFactory) ctx.lookup("ConnectionFactory"); connection = factory.createTopicConnection(); session = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); messageProducer = session.createProducer(topic); ObjectMessage message = session.createObjectMessage(); // here we create a NewsEntity, that will be sent in JMS message NewsEntity e = new NewsEntity(); e.setTitle(title); e.setBody(body); message.setObject(e); messageProducer.send(message); messageProducer.close(); connection.close(); response.sendRedirect("ListNews");
But when I post message, I get the error 'Internal Exception: org.postgresql.util.PSQLException: ERROR: null value in column "id" violates not-null constraint. Call: INSERT INTO NEWSENTITY (ID, TITLE, BODY) VALUES (?, ?, ?)'
I assume this problem occured because I could not provide the annotation @GeneratedValue as GenerationType.AUTO in NewsEntity Class since the J2EE version is 1.4. Most of the annotation types are not supported in 1.4.
package ejb; import java.io.Serializable; import javax.persistence.Entity; //import javax.persistence.GeneratedValue; //import javax.persistence.GenerationType; import javax.persistence.Id; //import javax.persistence.Table; @Entity //@Table(name="NewsEntity", schema="public", catalog="postgres") public class NewsEntity implements Serializable { private static final long serialVersionUID = 1L; @Id //@GeneratedValue(strategy = GenerationType.AUTO) private Long id; private String title; private String body;
If I remove the comment of the lines in Bold, I will get error - Unknown class while building the application.
Can any one provide me the way to define that the id field in NewsEntity class will be auto-generated? If I can do so then I need to pass value to id field while posting data to JMS topic. Thank you for your kind attention.
Regards
Rajesh