![](/img/trans.png)
[英]PreparedStatement IF EXISTS throws: org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0
[英]PSQLException: The column index is out of range: 7, number of columns: 6 - Postgres beginner
這是我正在構建用於示例網站的數據庫。
我正在使用游戲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);
}
}
有些東西有手工完成的屬性,有些則沒有,只是我試圖了解所有可以設置的方法(允許的是什么,你需要手動做什么,可以用哪種方式處理)。
我試圖在數據庫中保留用戶。 它包含所有數據,但由於某種原因,它說我試圖使用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)
這有點舊,但我剛剛在Play 1.x上構建的舊應用程序遇到了同樣的錯誤,我升級了一些庫,所以我認為這可能會幫助其他人。 以下之一可能會修復錯誤:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.