· 8 years ago · Nov 16, 2017, 02:08 PM
1@Entity
2@Table(name="project")
3public class Project implements Serializable{
4
5 private static final long serialVersionUID = 1L;
6
7 @Id
8 @GeneratedValue(strategy=GenerationType.AUTO)
9 @Column(name="id")
10 private int id;
11
12 @Column(name="teamId")
13 private int teamId;
14
15 //private String Rentabiliteit;
16
17 @Column
18 //@Index(name="IProject_status",columnNames="Status")
19 private String status;
20
21 @Column
22 //@Index(name="IProject_naam",columnNames="Naam")
23 private String naam;
24 //public Prototype m_Prototype;
25 //public Team m_Team;
26
27}
28
29CREATE TABLE IF NOT EXISTS `project` (
30`id` int(11) NOT NULL,
31`teamId` int(11) DEFAULT NULL,
32`status` varchar(255) DEFAULT NULL,
33`naam` varchar(255) DEFAULT NULL
34 ) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=latin1;
35
36Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
37 Unknown column 'project0_.team_id' in 'field list'
38
39spring:
40
41mvc:
42 view:
43 prefix: /WEB-INF/jsp/
44 suffix: .jsp
45
46datasource:
47 url: jdbc:mysql://localhost:3306/oxyplast
48 username: oxyplastuser
49 password: oxyplastuserpw
50
51jpa:
52 properties:
53 hibernate:
54 current_session_context_class: org.springframework.orm.hibernate4.SpringSessionContext
55 namingStrategy: org.hibernate.cfg.DefaultNamingStrategy
56
57spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.DefaultComponentSafeNamingStrategy
58
59spring-boot-starter-data-jpa: âž¡ 1.5.2.RELEASE
60 hibernate-core:5.0.12.Final
61
62PhysicalNamingStrategyStandardImpl
63
64public class PhysicalNamingStrategyImpl extends PhysicalNamingStrategyStandardImpl implements Serializable {
65
66 public static final PhysicalNamingStrategyImpl INSTANCE = new PhysicalNamingStrategyImpl();
67
68 @Override
69 public Identifier toPhysicalTableName(Identifier name, JdbcEnvironment context) {
70 String nameModified;
71 // Do whatever you want with the name modification
72 return new Identifier(nameModified, name.isQuoted());
73 }
74
75}
76
77 @Override
78 public Identifier toPhysicalColumnName(Identifier name, JdbcEnvironment context) {
79 String nameModified;
80 // Do whatever you want with the name modification
81 return new Identifier(nameModified, name.isQuoted());
82 }
83
84properties.put("hibernate.physical_naming_strategy", "my.Package.PhysicalNamingStrategyImpl");
85
86import org.springframework.beans.factory.annotation.Qualifier;
87import org.springframework.beans.factory.annotation.Value;
88import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
89import org.springframework.boot.context.properties.ConfigurationProperties;
90import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
91import org.springframework.context.annotation.Bean;
92import org.springframework.context.annotation.Configuration;
93import org.springframework.context.annotation.Primary;
94import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
95import org.springframework.orm.jpa.JpaTransactionManager;
96import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
97import org.springframework.transaction.PlatformTransactionManager;
98import org.springframework.transaction.annotation.EnableTransactionManagement;
99
100import javax.persistence.EntityManagerFactory;
101import javax.sql.DataSource;
102import java.util.HashMap;
103import java.util.Map;
104
105
106@Configuration
107@EnableTransactionManagement
108@EnableJpaRepositories(
109 entityManagerFactoryRef = "entityManagerFactory",
110 basePackages = { "com.xxxxxx.repository" }
111)
112public class SharedDataSourceConfig {
113
114 @Value("${startup.ddl-auto}")
115 String hbm2ddl;
116
117 @Primary
118 @Bean(name = "dataSource")
119 @ConfigurationProperties("spring.datasource.shared")
120 public DataSource customerDataSource() {
121 return DataSourceBuilder.create().build();
122 }
123
124 @Primary
125 @Bean(name = "entityManagerFactory")
126 public LocalContainerEntityManagerFactoryBean entityManagerFactory(
127 EntityManagerFactoryBuilder builder,
128 @Qualifier("dataSource") DataSource dataSource) {
129 Map<String, Object> properties = new HashMap<String, Object>();
130 properties.put("hibernate.hbm2ddl.auto", hbm2ddl);
131 properties.put("hibernate.physical_naming_strategy", "my.package.PhysicalNamingStrategyImpl");
132 return builder
133 .dataSource(dataSource)
134 .packages(PackageScannerHelper.getPackagesToScan())
135 .persistenceUnit("shared")
136 .properties(properties)
137 .build();
138 }
139
140 @Primary
141 @Bean(name = "transactionManager")
142 public PlatformTransactionManager transactionManager(
143 @Qualifier("entityManagerFactory") EntityManagerFactory
144 entityManagerFactory
145 ) {
146 return new JpaTransactionManager(entityManagerFactory);
147 }
148}
149
150@Column(name=""teamId"")
151
152private int teamId;