我有这段代码:
.gChild {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
这个主要
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="project-unit" transaction-type="RESOURCE_LOCAL">
<class>model.Product</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="org.postgresql.Driver" />
<property name="openjpa.ConnectionUserName" value="postgres" />
<property name="openjpa.ConnectionPassword" value="xxx" />
<property name="openjpa.ConnectionURL" value="jdbc:postgresql://localhost:5432/project" />
<property name="openjpa.jdbc.DBDictionary" value="postgres" />
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(SchemaAction=add,ForeignKeys=true)" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
</properties>
</persistence-unit>
</persistence>
和这个产品类: 包模型;
import model.*;
import javax.persistence.*;
public class pruebaMain {
public static void main(String [] args){
EntityManagerFactory emf = Persistence.createEntityManagerFactory("project-unit");
EntityManager em = emf.createEntityManager();
Product product = new Product();
product.setName("cheese");
product.setCode(21421);
product.setDescription("Test description");
EntityTransaction tx= em.getTransaction();
tx.begin();
em.persist(product);
tx.commit();
em.close();
emf.close();
}
}
但是,当我尝试代码时,我有这个错误:
import javax.persistence.*;
@Entity
public class Product {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
long code;
@Column(nullable=false,length=50)
String name;
@Column(nullable=false,length=500)
String description;
@Column(nullable=false)
int stock;
//builders
public Product(){
this.code=0;
this.name="";
this.description="";
this.stock=0;
}
public Product(long code, String name, String description,int stock){
this.code=code;
this.name=name;
this.name=description;
this.stock=stock;
}
//get & set
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getStock() {
return stock;
}
public void setStock(int stock) {
this.stock = stock;
}
}
我不知道是什么问题。我指定了ConnectionDriverName并添加到构建路径:postgresql-jdbc4.jar,postgresql-9.3-1100.jdbc41.jar
谢谢!
答案 0 :(得分:0)
我解决了。我把persistence.xml放在一个错误的文件夹中,现在它在META-INF中,它可以工作!