[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Equivalent of @GeneratedValue in JBoss-4.0.5.GA

rajesh.r77 do-not-reply at jboss.com
Thu Oct 16 06:04:03 EDT 2008

   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.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4182599#4182599

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4182599

More information about the jboss-user mailing list