-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Annotations - session.save fails after moving to annotations
PostPosted: Fri Oct 19, 2007 2:23 pm 
Newbie

Joined: Fri Oct 19, 2007 2:07 pm
Posts: 1
I just started using hibernate (version 3.2.5) 2 weeks ago. I got an application up and running and everything looks great.

Yesterday I started moving to annotations (3.3.0). It's a simple application using MySQL and I thought everything was working great. The code was reading from the DB no problem and displaying data to the end user.

Then I tried to insert a record (session.save()). Bam. stacktrace city. When I don't use annotations, I can save just fine. But using annotations, there is something probably very basic that I'm doing wrong.

The name of the table is "scheduled_message". The name for my pojo is ScheduledMessageData.

For some reason, it thinks the table it should insert into is scheduledmessagedata. But the @table is in my pojo is:

@Table(appliesTo="scheduled_message")

It reads from the table just fine. But insert fails. I tried both currentSession and openSession. Same result. I've searched documentation and the web. Nothing is jumping out at me what I'm doing wrong. Ideas?

I've posted both the stack trace (immediately following) and my pojo all the way at the end.

Here is the stack trace:
org.hibernate.exception.SQLGrammarException: could not insert: [com.m4.components.persist.data.ScheduledMessageData]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy14.save(Unknown Source)
at com.m4.components.dao.ScheduledMessageDao.insert(ScheduledMessageDao.java:54)
at com.m4.components.mq.dispatcher.MessageRunnable.addResponseMessages(MessageRunnable.java:106)
at com.m4.components.mq.dispatcher.MessageRunnable.messagePostProcessing(MessageRunnable.java:90)
at com.m4.components.mq.dispatcher.MessageRunnable.run(MessageRunnable.java:57)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:417)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:269)
at java.util.concurrent.FutureTask.run(FutureTask.java:123)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Table 'm4sandbox.scheduledmessagedata' doesn't exist
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3256)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1313)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1585)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1500)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1485)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)


HERE IS THE POJO:

package com.m4.components.persist.data;

import org.hibernate.annotations.NamedNativeQuery;
import org.hibernate.annotations.Table;

import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Enumerated;
import javax.persistence.EnumType;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Entity
@Table(appliesTo="scheduled_message")
@NamedNativeQuery(name="sp_mq_retrieve_message",
callable=true,
query="{ call sp_mq_retrieve_message(:messageType) }",
resultClass=com.m4.components.persist.data.ScheduledMessageData.class)

public class ScheduledMessageData extends BaseData {
public enum MessageType {
NO_FAILOVER_MESSAGE_TYPE, // Never used in the database
// The types of messages the message queue can handle
TEST, // Never used in production. Just for testing
TEST_FAILOVER, // Never used in production. Just for testing
TEST_RESPONSE, // Never used in production. Just for testing
NEVER_DELETE, // used for database locking. this row should never be deleted in the database
RSS_FEED_MTV,
TRANSCODE,
CDN_UPLOAD
// Other types of messages for a generic site message queue as well as specific
// upload_complete_notify
// copyright_violation_notify.
// thumbnail
}
public enum ObjectType {
NONE,
TEST, // Never used in production. Just for testing
MEMBER_VIDEO,
COPYRIGHT_VIOLATION_NOTIFY}

public enum Status {
MESSAGE_RESCHEDULED,
MESSAGE_SCHEDULED,
MESSAGE_PROCESSING}



@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;

@Column(name="message_type")
@Enumerated(EnumType.STRING)
private MessageType messageType;

@Column(name="object_type")
@Enumerated(EnumType.STRING)
private ObjectType objectType;

@Column(name="object_id")
private long objectId;

@Column(name="creation_date")
private Date creationDate;

@Column(name="scheduled_date")
private Date scheduledDate;

@Enumerated(EnumType.STRING)
private Status status;

private byte[] value;

@Column(name="try_count")
private int tryCount;

public ScheduledMessageData() {
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public MessageType getMessageType() {
return messageType;
}

public void setMessageType(MessageType messageType) {
this.messageType = messageType;
}

public ObjectType getObjectType() {
return objectType;
}

public void setObjectType(ObjectType objectType) {
this.objectType = objectType;
}

public long getObjectId() {
return objectId;
}

public void setObjectId(long objectId) {
this.objectId = objectId;
}

public Date getCreationDate() {
return creationDate;
}

public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}

public Date getScheduledDate() {
return scheduledDate;
}

public void setScheduledDate(Date scheduledDate) {
this.scheduledDate = scheduledDate;
}

public Status getStatus() {
return status;
}

public void setStatus(Status status) {
this.status = status;
}

public byte[] getValue() {
return value;
}

public void setValue(byte[] value) {
this.value = value;
}

public int getTryCount() {
return tryCount;
}

public void setTryCount(int tryCount) {
this.tryCount = tryCount;
}

public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("ScheduledMessageData:");
sb.append("\n\tid: ").append(id);
sb.append("\n\tmessage type: ").append(messageType);
sb.append("\n\tobject id: ").append(objectId);
sb.append("\n\tobject type: ").append(objectType);
sb.append("\n\tcreation date: ").append(creationDate);
sb.append("\n\tscheduledDate: ").append(scheduledDate);
sb.append("\n\tstatus: ").append(status);
sb.append("\n\ttry count: ").append(tryCount);
return sb.toString();
}
}



Thanks!

Randy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.