作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 spring 4+ hibernate 4.3 + psql 9.5 应用程序,并遇到了一些驼峰字段转换问题。
Hibernate: select trainservi0_.trainServiceId as trainSer1_16_, trainservi0_.category as category2_16_, trainservi0_.date as date3_16_, trainservi0_.description as descript4_16_, trainservi0_.name as name5_16_, trainservi0_.status as status6_16_, trainservi0_.trainNumber as trainNum7_16_, trainservi0_.version as version8_16_ from tms.public.train_service trainservi0_
2016-02-29 13:09:34 WARN SqlExceptionHelper:144 - SQL Error: 0, SQLState: 42703
2016-02-29 13:09:34 ERROR SqlExceptionHelper:146 - ERROR: column trainservi0_.trainserviceid does not exist
Perhaps you meant to reference the column "trainservi0_.trainServiceId".
这是我的配置:
public class DataBaseProdConfig {
@Resource
private Environment env;
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(env.getRequiredProperty("db.entity.package"));
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setJpaProperties(getHibernateProperties());
return em;
}
@Bean
public DataSource dataSource() {
BasicDataSource ds = new BasicDataSource();
ds.setUrl(env.getRequiredProperty("db.url"));
ds.setDriverClassName(env.getRequiredProperty("db.driver"));
ds.setUsername(env.getRequiredProperty("db.username"));
ds.setPassword(env.getRequiredProperty("db.password"));
ds.setInitialSize(Integer.valueOf(env.getRequiredProperty("db.initialSize")));
ds.setMinIdle(Integer.valueOf(env.getRequiredProperty("db.minIdle")));
ds.setMaxIdle(Integer.valueOf(env.getRequiredProperty("db.maxIdle")));
ds.setTimeBetweenEvictionRunsMillis(Long.valueOf(env.getRequiredProperty("db.timeBetweenEvictionRunsMillis")));
ds.setMinEvictableIdleTimeMillis(Long.valueOf(env.getRequiredProperty("db.minEvictableIdleTimeMillis")));
ds.setTestOnBorrow(Boolean.valueOf(env.getRequiredProperty("db.testOnBorrow")));
ds.setValidationQuery(env.getRequiredProperty("db.validationQuery"));
return ds;
}
@Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager manager = new JpaTransactionManager();
manager.setEntityManagerFactory(entityManagerFactory().getObject());
return manager;
}
public Properties getHibernateProperties() {
try {
Properties properties = new Properties();
InputStream is = getClass().getClassLoader().getResourceAsStream("hibernate.properties");
properties.load(is);
return properties;
} catch (IOException e) {
throw new IllegalArgumentException("Can't find 'hibernate.properties' in classpath!", e);
}
}
这是我的实体:
@Entity
@Table(name = "train_service", schema = "public", catalog = "tms")
public class TrainServiceEntity {
private Long trainServiceId;
@Id
@SequenceGenerator(name="train_service_trainServiceId_seq",
sequenceName="train_service_trainServiceId_seq",
allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator="train_service_trainServiceId_seq")
@Column(name = "trainServiceId")
public Long getTrainServiceId() {
return trainServiceId;
}
public void setTrainServiceId(Long trainServiceId) {
this.trainServiceId = trainServiceId;
}
....
}
因此 Hibernate 将 'trainServiceId' 翻译为 'trainserviceid' ,但在日志中我看到了正确的字段名称:
Hibernate: select trainservi0_.trainServiceId as trainSer1_16_, ...
我需要做什么,强制 Hibernate 不将字段名称转换为小写?
最佳答案
关于java - JPA Hibernate 驼峰字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35697121/
如 this question适用于“大型”Visual Studio 和 Resharper,我也希望在 VS Code 中看到该功能。 滚动浏览 shortcut list对于 VS Code,我
我是一名优秀的程序员,十分优秀!