这是我正在构建用于示例网站的数据库。
我正在使用play 1.3
这是结构:
@Entity
public class BlogUser extends BlogModel {
@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.TABLE)
public Long id;
public String firstName;
public String lastName;
@Column(nullable = false)
public String username;
@Column(nullable = false)
public String password;
@Column(nullable = false)
public String email;
public BlogUser(String fName, String lName, String uName, String pWord, String email1) {
firstName = fName;
lastName = lName;
username = uName;
password = pWord;
email = email1;
}
}
这是来自控制器的命令
public static void registerSubmit(String firstName, String lastName, String username, String password, String email) throws FileNotFoundException {
BlogUser user = new BlogUser(firstName, lastName, username, password, email);
//persists the entity in the database
try {
user.save();
}
catch (PersistenceException e) {
File file = new File("testsalotofthem.txt");
PrintStream ps = new PrintStream(file);
e.printStackTrace(ps);
}
}
有些东西是手动完成的,有些则没有,只是我试图了解所有可以设置的方法(允许的是什么,你需要手动做什么,可以用哪种方式处理)。 / p>
我正在尝试在数据库中保留用户。它包含所有数据,但出于某种原因,它说我试图使用7列而不是6列。
数据来自网站,该命令是用户输入信息的地方。
任何解决这个问题的提示都会有所帮助,因为我很难过。
这是堆栈跟踪:
javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not insert: [models.BlogUser]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:999)
at play.db.jpa.JPABase._save(JPABase.java:45)
at play.db.jpa.GenericModel.save(GenericModel.java:232)
at controllers.Application.registerSubmit(Application.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:524)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:475)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:451)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:446)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:160)
at play.server.PlayHandler$NettyInvocation.execute(PlayHandler.java:267)
at play.Invoker$Invocation$1.apply(Invoker.java:290)
at play.Invoker$Invocation$1.apply(Invoker.java:287)
at play.db.jpa.JPA.withTransaction(JPA.java:258)
at play.db.jpa.JPA.withinFilter(JPA.java:217)
at play.db.jpa.JPAPlugin$TransactionalFilter.withinFilter(JPAPlugin.java:299)
at play.Invoker$Invocation.withinFilter(Invoker.java:271)
at play.Invoker$Invocation.run(Invoker.java:287)
at play.server.PlayHandler$NettyInvocation.run(PlayHandler.java:245)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.exception.DataException: could not insert: [models.BlogUser]
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:135)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3087)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3509)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:286)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:996)
... 28 more
Caused by: org.postgresql.util.PSQLException: The column index is out of range: 7, number of columns: 6.
at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:53)
at org.postgresql.core.v3.SimpleParameterList.setLiteralParameter(SimpleParameterList.java:114)
at org.postgresql.jdbc2.AbstractJdbc2Statement.bindLiteral(AbstractJdbc2Statement.java:2172)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setLong(AbstractJdbc2Statement.java:1227)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setLong(NewProxyPreparedStatement.java:170)
at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:57)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:93)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
at org.hibernate.type.ComponentType.nullSafeSet(ComponentType.java:358)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrateId(AbstractEntityPersister.java:2823)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2792)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3064)
... 37 more
编辑:从play jpa GenericModel.java
添加了save()方法public <T extends JPABase> T save() {
_save();
return (T) this;
}
Edit2:添加了BlogUser表
Table "public.bloguser"
Column | Type | Modifiers
-----------+------------------------+-----------
id | bigint | not null
email | character varying(255) | not null
firstname | character varying(255) |
lastname | character varying(255) |
password | character varying(255) | not null
username | character varying(255) | not null
Indexes:
"bloguser_pkey" PRIMARY KEY, btree (id)
答案 0 :(得分:2)
这有点旧,但我刚刚在Play 1.x上构建的旧应用程序遇到了同样的错误,我正在升级一些库,所以我认为这可能会帮助其他人。以下之一可能会修复错误: