Olá,
estou com duvida como usar @GenericGenerator strategy = “uuid”) estou tentando gerar um registro
@RunWith(SpringJUnit4ClassRunner.class)
public class UserMemberDAOImplTest extends BaseTest{
private UserMemberDAO userMemberDAO;
public UserMemberDAO getUserMemberDAO() {
return userMemberDAO;
}
@Autowired
public void setUserMemberDAO(UserMemberDAO userMemberDAO) {
this.userMemberDAO = userMemberDAO;
}
@Test
@Transactional
public void testPersistUserMember() throws Exception {
UserMember user = new UserMember();
user.setCreateTime(new Date());
user.setLogonName("Teste");
user.setUpdateTime(new Date());
userMemberDAO.persist(user);
}
}
e me da erro conforme abaixo ERROR: org.hibernate.util.JDBCExceptionReporter - Nome de objeto ‘UserMember’ inválido.???
O que poderá ser ???/
abs
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="UserMember")
public class UserMember {
@ Id
@GeneratedValue (generator = "system-uuid")
@GenericGenerator (name = "system-uuid", strategy = "uuid")
@Column(name = "id", unique = true, nullable = false, length = 32)
private String id;
@ Column (updatable = false, nullable = false, length = 20)
private String logonName;
@ Temporal (TemporalType.TIMESTAMP)
@ Column (updatable = false, length = 20)
private Date createTime;
@ Temporal (TemporalType.TIMESTAMP)
private Date updateTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLogonName() {
return logonName;
}
public void setLogonName(String logonName) {
this.logonName = logonName;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
//
}
//
public interface DAO {
/**
* Método de procura genérico, baseado na entidade passada como exemplo.
*
* @param entity
* A entidade utilizada como exemplo na busca.
* @return A entidade caso ela seja encontrada, <code>null</code> do
* contrário.
* @throws DataAccessException
*/
<T> T find(Class<T> classe, Serializable id) throws DAOException ;
/**
* Método de atualização genérico, faz a atualização dos dados da entidade
* informada.
*
* @param entity
* A entidade a ser atualizada.
* @throws DataAccessException
*/
<T> void merge(T entity) throws DAOException;
/**
* Método de persistência genérico, salva no banco a entidade informada.
*
* @param entity
* A entidade a ser persistida.
* @throws DataAccessException
*/
<T> void persist(T entity) throws DAOException;
/**
* Método de remoção genérico, remove do banco a entidade informada.
*
* @param entity
* A entidade a ser removida.
* @throws Exception
*/
<T> void remove(T entity) throws DAOException;
/**
* Método de procura genérico que traz todas as entidades existentes, do
* tipo da classe informada.
*
* @param classe
* A classe da entidade procurada.
* @return Uma lista com todas as entidades encontradas.
* @throws DataAccessException
*/
<T> Collection<T> findAll(Class<T> classe) throws DAOException;
}
//
public interface UserMemberDAO extends DAO{
/**
*
* Método que seleciona todos cartões por nome
* para envio do destinatário.
*
* @author Paulo
*
*/
}
//
@Repository
@SuppressWarnings("unchecked")
public class UserMemberDAOImpl extends GenericDAO implements UserMemberDAO{
/** construtor */
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(UserMemberDAOImpl.class);
@Autowired
public UserMemberDAOImpl(HibernateTemplate template) {
super(template);
}
}
28/12/2009 15:20:54 org.hibernate.cfg.annotations.Version <clinit>
INFO: Hibernate Annotations 3.4.0.GA
28/12/2009 15:20:54 org.hibernate.annotations.common.Version <clinit>
INFO: Hibernate Commons Annotations 3.1.0.GA
28/12/2009 15:20:54 org.hibernate.cfg.search.HibernateSearchEventListenerRegister enableHibernateSearch
INFO: Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
28/12/2009 15:20:54 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: domain.UserMember
28/12/2009 15:20:54 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity domain.UserMember on table UserMember
28/12/2009 15:20:54 org.hibernate.cfg.AnnotationBinder bindClass
INFO: Binding entity from annotated class: domain.CardModel
28/12/2009 15:20:54 org.hibernate.cfg.annotations.EntityBinder bindTable
INFO: Bind entity domain.CardModel on table Card
28/12/2009 15:20:54 org.hibernate.cfg.AnnotationConfiguration secondPassCompile
INFO: Hibernate Validator not found: ignoring
WARN : org.hibernate.cfg.SettingsFactory - Overriding release mode as connection provider does not support 'after_statement'
WARN : net.sf.ehcache.config.ConfigurationFactory - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/dbucci/.m2/repository/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar!/ehcache-failsafe.xml
WARN : org.hibernate.cache.EhCacheProvider - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
WARN : org.hibernate.cache.EhCacheProvider - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
INFO : dao.GenericDAO - salvando domain.UserMember@8b677f
Hibernate:
select
newid()
Hibernate:
insert
into
UserMember
(createTime, logonName, updateTime, id)
values
(?, ?, ?, ?)
WARN : org.hibernate.util.JDBCExceptionReporter - SQL Error: 208, SQLState: S0002
ERROR: org.hibernate.util.JDBCExceptionReporter - Nome de objeto 'UserMember' inválido.
ERROR: org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not insert: [domain.UserMember]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2272)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2665)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateTemplate$27.doInHibernate(HibernateTemplate.java:811)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:809)
at dao.GenericDAO.persist(GenericDAO.java:57)
at dao.UserMemberDAOImplTest.testPersistUserMember(UserMemberDAOImplTest.java:39)
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:597)
at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLException: Nome de objeto 'UserMember' inválido.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2252)
... 36 more