hibernate - postgres错误:线程“main”中的异常org.hibernate.exception.SQLGrammarException:无法提取ResultSet

时间:2016-08-12 18:08:45

标签: java postgresql hibernate jdbc

当我尝试构建这个系统时,发生了一些非常奇怪的事情。我没有对我的文件进行任何代码更改,我能够通过hibernate在我的java类中保存并从postgres获取数据。 今天我开始实现一个post方法来尝试通过rest json对象插入数据,但即使在我能做到这一点之前,我的测试(昨天运行完美无需任何代码更改)会随着下面的错误而崩溃。请帮忙!

Aug 12, 2016 11:05:34 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.2.Final}
Aug 12, 2016 11:05:34 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.max_fetch_depth=5, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.password=****, hibernate.connection.pool_size=5}
Aug 12, 2016 11:05:34 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 12, 2016 11:05:34 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Aug 12, 2016 11:05:34 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Aug 12, 2016 11:05:34 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://104.154.96.122/danstaging]
Aug 12, 2016 11:05:34 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****, dialect=org.hibernate.dialect.PostgreSQLDialect}
Aug 12, 2016 11:05:34 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Aug 12, 2016 11:05:34 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Aug 12, 2016 11:05:34 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Aug 12, 2016 11:05:34 AM org.hibernate.dialect.H2Dialect <init>
WARN: HHH000431: Unable to determine H2 database version, certain features may not work
Aug 12, 2016 11:05:53 AM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
Aug 12, 2016 11:05:53 AM org.hibernate.envers.boot.internal.EnversServiceImpl configure
INFO: Envers integration enabled? : true
Aug 12, 2016 11:05:54 AM org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl getIsolatedConnection
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@7a48e6e2] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
Hibernate: 
    call next value for hibernate_sequence
Aug 12, 2016 11:05:55 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42601
Aug 12, 2016 11:05:55 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: syntax error at or near "call"
  Position: 1
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
    at org.hibernate.id.enhanced.SequenceStructure$1.getNextValue(SequenceStructure.java:96)
    at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
    at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:412)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:673)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:665)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:660)
    at careers.nebula.ben.db.repository.signup.UserRepo.InsertUserData(UserRepo.java:23)
    at careers.nebula.ben.service.signup.UserInformation.InsertPrimaryUserInfo(UserInformation.java:39)
    at careers.nebula.ben.iws.signup.UserInformationIWS.userInformationPojo(UserInformationIWS.java:35)
    at careers.nebula.ben.testing.UserTesting.main(UserTesting.java:38)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
  Position: 1
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2310)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2023)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:421)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:166)
    at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
    ... 16 more
回复课程:

/**
 * 
 */
package careers.nebula.ben.db.repository.signup;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import careers.nebula.ben.db.enitity.User;

/**
 * @author Ankit_Nebula
 * get the user data object from service and store to DB using hibernate
 */
public class UserRepo {
    //note: need to create only one session factory for entire project. 
    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();

    public void InsertUserData(User userData){
                session.beginTransaction();
                session.save(userData);
                session.getTransaction().commit();
                session.close();
    }

    public User getUserData(int userID){
                User userData = new User();
                session = sessionFactory.openSession();
                session.beginTransaction();
                userData = (User)session.get(User.class, userID);
                session.close();
                return userData;
    }
}

hibernate.cfg.xml中:

<!--
  ~ Hibernate, Relational Persistence for Idiomatic Java
  ~
  ~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  ~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  -->
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:postgresql://104.154.96.122/danstaging</property>
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.connection.password">******</property>
       <!-- <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/nebuladb</property>
        <property name="hibernate.connection.username">*****</property>
        <property name="hibernate.connection.password">****</property>-->
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.pool_size">1</property>
        <property name="hibernate.connection.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping class="careers.nebula.ben.db.enitity.User"/>
    </session-factory>
</hibernate-configuration>

hibernate错误日志:

Hibernate: 
    call next value for hibernate_sequence
Aug 12, 2016 11:59:33 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42601
Aug 12, 2016 11:59:33 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: syntax error at or near "call"
  Position: 1
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
    at org.hibernate.id.enhanced.SequenceStructure$1.getNextValue(SequenceStructure.java:96)
    at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
    at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:412)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
    at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
    at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
    at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:673)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:665)
    at org.hibernate.internal.SessionImpl.save(SessionImpl.java:660)
    at careers.nebula.ben.db.repository.signup.UserRepo.InsertUserData(UserRepo.java:23)
    at careers.nebula.ben.service.signup.UserInformation.InsertPrimaryUserInfo(UserInformation.java:39)
    at careers.nebula.ben.iws.signup.UserInformationIWS.userInformationPojo(UserInformationIWS.java:35)
    at careers.nebula.ben.testing.UserTesting.main(UserTesting.java:38)
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "call"
  Position: 1
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2310)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2023)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:421)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:166)
    at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
    ... 16 more

用户实体:

@Entity
@Table (name = "users")
public class User {
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    private String firstName;  //@column (name="") to configure columns 
    private String lastName;
    private String preferredName;
    private String phoneNumber;
    private String email;
    private String photoUrl;
    private String videoUrl;
    private String personalWebsiteUrl;
    private String fbUrl;
    private String linkedinUrl;
    private String goals;
    private String aboutMe;
    private Boolean currentlyEmployeed;
    private Boolean currentlyInSchool;
    private String highestQualification;
    private double user_rating;
    private int skills_id; //foreign key to skills table
    private int location_id; //foreign key to location table 

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getPreferredName() {
        return preferredName;
    }
    public void setPreferredName(String preferredName) {
        this.preferredName = preferredName;
    }
    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public String getPhotoUrl() {
        return photoUrl;
    }
    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }
    public String getVideoUrl() {
        return videoUrl;
    }
    public void setVideoUrl(String videoUrl) {
        this.videoUrl = videoUrl;
    }
    public String getPersonalWebsiteUrl() {
        return personalWebsiteUrl;
    }
    public void setPersonalWebsiteUrl(String personalWebsiteUrl) {
        this.personalWebsiteUrl = personalWebsiteUrl;
    }
    public String getGoals() {
        return goals;
    }
    public void setGoals(String goals) {
        this.goals = goals;
    }
    public String getAboutMe() {
        return aboutMe;
    }
    public void setAboutMe(String aboutMe) {
        this.aboutMe = aboutMe;
    }
    public Boolean getCurrentlyEmployeed() {
        return currentlyEmployeed;
    }
    public void setCurrentlyEmployeed(Boolean currentlyEmployeed) {
        this.currentlyEmployeed = currentlyEmployeed;
    }
    public Boolean getCurrentlyInSchool() {
        return currentlyInSchool;
    }
    public void setCurrentlyInSchool(Boolean currentlyInSchool) {
        this.currentlyInSchool = currentlyInSchool;
    }
    public String getHighestQualification() {
        return highestQualification;
    }
    public void setHighestQualification(String highestQualification) {
        this.highestQualification = highestQualification;
    }
    public double getUser_rating() {
        return user_rating;
    }
    public void setUser_rating(double user_rating) {
        this.user_rating = user_rating;
    }
    public String getFbUrl() {
        return fbUrl;
    }
    public void setFbUrl(String fbUrl) {
        this.fbUrl = fbUrl;
    }
    public String getLinkedinUrl() {
        return linkedinUrl;
    }
    public void setLinkedinUrl(String linkedinUrl) {
        this.linkedinUrl = linkedinUrl;
    }
    public int getSkills_id() {
        return skills_id;
    }
    public void setSkills_id(int skills_id) {
        this.skills_id = skills_id;
    }
    public int getLocation_id() {
        return location_id;
    }
    public void setLocation_id(int location_id) {
        this.location_id = location_id;
    }


}

0 个答案:

没有答案