JPA批更新似乎是每批插入一个更新
我正在尝试使用JPA/EclipseLink 2.4.1和使用Merlia驱动程序的MSSQL服务器进行批持久化。根据数据库与日志的反应方式(如下所示),似乎每个插入都发生在自己的批中 我将持久性xml设置如下:JPA批更新似乎是每批插入一个更新,jpa,eclipselink,jpa-2.0,Jpa,Eclipselink,Jpa 2.0,我正在尝试使用JPA/EclipseLink 2.4.1和使用Merlia驱动程序的MSSQL服务器进行批持久化。根据数据库与日志的反应方式(如下所示),似乎每个插入都发生在自己的批中 我将持久性xml设置如下: <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"> <persistence-unit name="EclipseLinkPersistenceUnit">
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="EclipseLinkPersistenceUnit">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.mypackage.ViewInDatabaseEntity</class>
...
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.inet.tds.PDataSource4"/>
<property name="eclipselink.jdbc.batch-writing" value="jdbc" />
<property name="eclipselink.jdbc.batch-writing.size" value="1000" />
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>
</persistence>
这似乎表明每个插入都是在自己的批中进行的。按照persistence.xml;我启用了
<property name="eclipselink.jdbc.batch-writing" value="jdbc" />
当序列策略要求在每个insert语句后查找指定的序列值时,批处理将不起作用。尝试使用表排序或一些允许预先分配序列值的策略,以便对它们进行批处理
[EL Finer]: transaction: 2014-05-02 16:42:49.963--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--begin transaction
...
[EL Finest]: query: 2014-05-02 16:42:49.964--ClientSession(27801544)--Thread(Thread[qtp18824904-22,5,main])--Execute query ValueReadQuery(name="SEQ_GEN_SEQUENCE" sql="SELECT @@IDENTITY")
[EL Finer]: sql: 2014-05-02 16:42:56.422--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--Begin batch statements
[EL Fine]: sql: 2014-05-02 16:42:56.422--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--INSERT INTO dbo.ViewInDatabaseEntity(property1, property4, property3, property2, property5) VALUES (?, ?, ?, ?, ?)
[EL Fine]: sql: 2014-05-02 16:42:56.422--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])-- bind => [ABC, DEF, GHI, JKL, 0.3465443]
[EL Finer]: sql: 2014-05-02 16:42:56.422--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--End Batch Statements
[EL Fine]: sql: 2014-05-02 16:42:56.505--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--SELECT @@IDENTITY
[EL Finest]: sequencing: 2014-05-02 16:42:56.506--UnitOfWork(15091453)--Thread(Thread[qtp18824904-22,5,main])--assign sequence to the object (89,588 -> com.mypackage.ViewInDatabaseEntity@945ed6f5)
[EL Finest]: query: 2014-05-02 16:42:56.507--UnitOfWork(15091453)--Thread(Thread[qtp18824904-22,5,main])--Execute query InsertObjectQuery(com.mypackage.ViewInDatabaseEntity@5d6e305d)
[EL Finest]: query: 2014-05-02 16:42:56.507--ClientSession(27801544)--Thread(Thread[qtp18824904-22,5,main])--Execute query ValueReadQuery(name="SEQ_GEN_SEQUENCE" sql="SELECT @@IDENTITY")
[EL Finer]: sql: 2014-05-02 16:42:56.507--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--Begin batch statements
[EL Fine]: sql: 2014-05-02 16:42:56.507--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--INSERT INTO dbo.ViewInDatabaseEntity(property1, property4, property3, property2, property5) VALUES (?, ?, ?, ?, ?)
[EL Fine]: sql: 2014-05-02 16:42:56.507--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])-- bind => [ABC, ZYX, WVU, RST, 0.35345634]
[EL Finer]: sql: 2014-05-02 16:42:56.507--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--End Batch Statements
[EL Fine]: sql: 2014-05-02 16:42:56.591--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--SELECT @@IDENTITY
[EL Finest]: sequencing: 2014-05-02 16:42:56.592--UnitOfWork(15091453)--Thread(Thread[qtp18824904-22,5,main])--assign sequence to the object (89,666 -> com.mypackage.ViewInDatabaseEntity@5d6e305d)
...
[EL Finer]: transaction: 2014-05-02 16:42:56.598--ClientSession(27801544)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--commit transaction
[EL Finest]: connection: 2014-05-02 16:42:56.605--ServerSession(2644459)--Connection(28732068)--Thread(Thread[qtp18824904-22,5,main])--Connection released to connection pool [default].
<property name="eclipselink.jdbc.batch-writing" value="jdbc" />
@javax.persistence.Table(name = "ViewInDatabase", schema = "dbo")
@Entity
@EqualsAndHashCode
@Getter
@Setter
public class ViewInDatabaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private int id;
@javax.persistence.Column(name = "id", nullable = false, insertable = false, updatable = false,
length = 0, precision = 0)
@Basic
public int getId() {
return id;
}
@javax.persistence.Column(name = "property1", nullable = false, insertable = true,
updatable = true, length = 20, precision = 0)
@Basic
private String property1;
@javax.persistence.Column(name = "property2", nullable = true, insertable = true, updatable = true,
length = 0, precision = 0)
@Basic
private String property2;
@javax.persistence.Column(name = "property3", nullable = true, insertable = true,
updatable = true, length = 0, precision = 0)
@Basic
private String property3;
@javax.persistence.Column(name = "property4", nullable = false, insertable = true, updatable = true,
length = 10, precision = 0)
@Basic
private String property4;
@javax.persistence.Column(name = "property5", nullable = true, insertable = true, updatable = true,
length = 0, precision = 0)
@Basic
private BigDecimal property5;
@javax.persistence.Column(name = "property6", nullable = false, insertable = false,
updatable = false, length = 0, precision = 0)
@Basic
private int property6;
@javax.persistence.Column(name = "property7", nullable = false, insertable = false,
updatable = false, length = 0, precision = 0)
@Basic
private Date property7;
}