hibernate没有找到架构

时间:2015-02-11 08:53:48

标签: hibernate postgresql wildfly

有野生动物8.2.0。

有一个postgres db和一个名为'authorization_central'的模式。

实体模式是:



@XmlRootElement(name = "users")

@Entity

@Table(name = "tblusers", schema = "authorization_central")

public class User implements Serializable {



    private static final long serialVersionUID = 1L;

    @Id

    @GeneratedValue(strategy = GenerationType.AUTO)

    private Long id;

    private String userName;

    private String password;



    @XmlElement

    public String getUserName() {

        return userName;

    }



    public void setUserName(String userName) {

        this.userName = userName;

    }



    @XmlElement

    public String getPassword() {

        return password;

    }



    public void setPassword(String password) {

        this.password = password;

    }



    @XmlElement

    public Long getId() {

        return id;

    }



    public void setId(Long id) {

        this.id = id;

    }



    @Override

    public int hashCode() {

        int hash = 0;

        hash += (id != null ? id.hashCode() : 0);

        return hash;

    }



    @Override

    public boolean equals(Object object) {

        // TODO: Warning - this method won't work in the case the id fields are not set

        if (!(object instanceof User)) {

            return false;

        }

        User other = (User) object;

        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {

            return false;

        }

        return true;

    }



    @Override

    public String toString() {

        return "domain.models.User[ id=" + id + " ]";

    }



}

persistence.xml是


<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence">

  <persistence-unit name="UserPersistenceUnit" transaction-type="JTA">

    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>domain.models.User</class>

    <properties>

      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>

      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1:5432/postgres"/>

      <property name="javax.persistence.jdbc.user" value="postgres"/>

      <property name="javax.persistence.jdbc.password" value="1234"/>

      <!--<property name="javax.persistence.jdbc.user" value="rastin"/>-->

      <!--<property name="javax.persistence.jdbc.password" value="bt_Ummah"/>-->

      <!--<property name="javax.persistence.schema-generation.database.action" value="create"/>-->

      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

      <property name="hibernate.show_sql" value="true"/>

      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

    </properties>

  </persistence-unit>

</persistence>

我的问题出在这堂课上:


@Transactional

public class EntityDao {



    @PersistenceContext(name = "UserPersistenceUnit")

    EntityManager entityManager;



    public void add(Object t) {

        try {

            System.out.println("start adding4.");

            if (entityManager == null) {

                System.out.println("entity manager is null.");

                entityManager = Persistence.

                        createEntityManagerFactory("UserPersistenceUnit").

                        createEntityManager();

                if (entityManager != null) {

                    System.out.println("entity manager created.");

                }

            }

//            entityManager.getTransaction().begin();

            entityManager.persist(t);

//            entityManager.getTransaction().commit();

        } catch (Exception e) {

            e.printStackTrace();

            System.out.println(e.getMessage());

        }

    }



}

发给我错误:

错误[org.hibernate.engine.jdbc.spi.SqlExceptionHelper](默认任务-7)未找到架构“AUTHORIZATION_CENTRAL”; SQL语句:

插入authorization_central.tblusers(密码,userName,id)值(?,?,?)[90079-173]


然后创建了一个名为rastinuser的用户。

创建了一个名为rastindb的数据库。

使用此用户和db登录。 psql -d rastindb -U rastinuser。

create schema authorization_central。

更改persistence.xml这两行:


<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1:5432/rastindb"/>

<property name="javax.persistence.jdbc.user" value="rastinuser"/>

\ dn命令:

List of schemas

         Name          |   Owner   

-----------------------+------------

authorization_central | rastinuser

public                | postgres

但已存在问题。

任何人都可以提供帮助吗?

感谢。

0 个答案:

没有答案