我有一个使用jpa / hibernate + mysql + spring并带有xml配置的maven应用程序,没有spring boot。我必须插入和删除大量数据,并且我读到postgresql允许generatetype.SEQUENCE可以大大加快批量插入或选择的速度。因此,我决定从mysql迁移到postgresql。但是我在配置和区分大小写方面遇到了麻烦:
我用hibernate / jpa注释@Entity和@Table(name = xxx)构建表。创建了大多数表,但没有创建,并且PostgreSQL启动错误:
org.postgresql.util.PSQLException: ERROR: relation "continuoustemperature" does not exist
当我检查数据库时,实际上未创建任何表“ continuoustemperature”。大多数表已创建并填充,但有些则没有。我读到有些人在使用postgresql时区分大小写有麻烦,但是尝试小写所有内容都无济于事。
ContinuousTemperature类:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
@Table(name="ContinuousTemperature")
public class ContinuousTemperature implements Serializable, HasPhysicalDataAtContinuousTime<ContinuousTemperature,Double>, Comparable<ContinuousTemperature>, PrintableAtCal, DeepCopyable<ContinuousTemperature>
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@Column(name = "CTid")
@XmlElement
private Long CTid;
@XmlElement
@Column(columnDefinition = "DATETIME(3) NOT NULL")
private Calendar measurementtime;
@XmlElement
private String unit;
@XmlElement
@Column(nullable = false, columnDefinition = "TINYINT(1)")
private boolean ismeasured;
@XmlElement(name="temperaturemeasured")
private double temperaturemeasured;
@XmlElement
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="temperaturesensorId")
private TemperatureSensor temperaturesensor;
我的数据库xml配置:
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
<context:property-placeholder location="classpath:config.properties"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driverClassName}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="${db.type}" />
<property name="showSql" value="false" />
</bean>
</property>
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.nodenet.domain" />
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.ejb.naming_strategy">${db.namingStrategy}</prop>
<!--
<prop key="hibernate.dialect">${db.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.default_schema">${db.schema}</prop>
-->
<prop key="hibernate.hbm2ddl.auto">${db.hbm2ddl}</prop>
<prop key="hibernate.jdbc.batch_size"> 50 </prop>
</props>
</property>
</bean>
<bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<jpa:repositories base-package="com.nodenet, com.nodenet.repository, com.nodenet.domain" />
config.properties:
db.driverClassName=org.postgresql.Driver
!db.url=jdbc:postgresql://localhost:3306/reallifepw3?rewriteBatchedStatements=true
db.url=jdbc:postgresql://localhost:5432/reallifepw3
db.username=postgres
!root
db.password=xxxxxxx
db.dialect=org.hibernate.dialect.PostgreSQL94Dialect
db.schema=
db.type=POSTGRESQL
db.namingStrategy=org.hibernate.cfg.ImprovedNamingStrategy
db.hbm2ddl=update
db.batch=50
为什么在其他人创建表时却没有创建这个特定表?