teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

設定ファイルを追記しました。

2018/04/01 08:45

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -48,4 +48,118 @@
48
48
  データの取得等はJpaRepositoryを使用しています。
49
49
  Tomcatを起動すると、insertしたデータが消えているので、テーブルをみてみると、TechSearchListEntityというテーブルができていて、値を入れると、Tomcatを起動してもデータは消えないようでした。
50
50
  @Table(name="TechSearchList")を定義していたので、TechSearchListというテーブルを見ていると思ったのですが、クラス名のテーブルが勝手に作られるものなのでしょうか。
51
- ご存知の方がいたら教えていただきたいです。
51
+ ご存知の方がいたら教えていただきたいです。
52
+
53
+ 設定ファイルを追記します。
54
+
55
+ persistence.xml
56
+ ```persistence.xml
57
+ <?xml version="1.0" encoding="UTF-8"?>
58
+ <persistence version="2.1"
59
+ xmlns="http://xmlns.jcp.org/xml/ns/persistence"
60
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
61
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
62
+ http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
63
+
64
+ <persistence-unit name="persistenceUnit"
65
+ transaction-type="RESOURCE_LOCAL">
66
+ <provider>org.hibernate.ejb.HibernatePersistence</provider>
67
+ <properties>
68
+ <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
69
+ <property name="hibernate.hbm2ddl.auto" value="create" />
70
+ <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
71
+ <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost/××××" />
72
+ <property name="hibernate.connection.password" value="××××××" />
73
+ <property name="hibernate.connection.username" value="user1" />
74
+ </properties>
75
+ </persistence-unit>
76
+ </persistence>
77
+ ```
78
+
79
+ application-config.xml
80
+ ```ここに言語を入力
81
+ <?xml version="1.0" encoding="UTF-8"?>
82
+
83
+ <beans xmlns="http://www.springframework.org/schema/beans"
84
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
85
+ xmlns:jdbc="http://www.springframework.org/schema/jdbc"
86
+ xmlns:tx="http://www.springframework.org/schema/tx"
87
+ xmlns:jpa="http://www.springframework.org/schema/data/jpa"
88
+ xmlns:context="http://www.springframework.org/schema/context"
89
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
90
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
91
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
92
+ http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
93
+ http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
94
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
95
+
96
+ <!-- Uncomment and add your base-package here:
97
+ <context:component-scan
98
+ base-package="org.springframework.samples.service"/> -->
99
+
100
+ <context:property-placeholder
101
+ location="classpath:spring/database.properties" />
102
+
103
+ <context:annotation-config />
104
+ <context:component-scan base-package="co.jp.TechMemo" />
105
+ <jpa:repositories base-package="co.jp.TechMemo.Repository" />
106
+
107
+
108
+ <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
109
+
110
+ <bean id="transactionManager"
111
+ class="org.springframework.orm.jpa.JpaTransactionManager">
112
+ <property name="entityManagerFactory" ref="entityManagerFactory" />
113
+ </bean>
114
+
115
+ <bean id="entityManagerFactory"
116
+ class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
117
+ <property name="jpaVendorAdapter">
118
+ <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
119
+ <property name="showSql" value="true" />
120
+ </bean>
121
+ </property>
122
+ <property name="persistenceUnitName" value="persistenceUnit" />
123
+ <property name="dataSource" ref="dataSource" />
124
+ <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
125
+ </bean>
126
+ <!-- jdbc -->
127
+ <bean class ="org.apache.commons.dbcp.BasicDataSource" id="dataSource">
128
+ <property name="driverClassName" value="${database.driverClassName}" />
129
+ <property name="url" value="${database.url}" />
130
+ <property name="username" value="${database.username}" />
131
+ <property name="password" value="${database.password}" />
132
+ </bean>
133
+
134
+ <bean class="org.springframework.jdbc.core.JdbcTemplate">
135
+ <constructor-arg ref="dataSource" />
136
+ </bean>
137
+
138
+ <jpa:repositories base-package="co.jp.springbook.TechMemo.Repository" />
139
+ </beans>
140
+ ```
141
+
142
+ mvc-config.xml
143
+ ```ここに言語を入力
144
+ <?xml version="1.0" encoding="UTF-8"?>
145
+
146
+ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
147
+ xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
148
+ xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
149
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
150
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
151
+
152
+ <!-- Uncomment and your base-package here -->
153
+ <context:component-scan base-package="co.jp.TechMemo.controller" />
154
+ <context:component-scan base-package="co.jp.TechMemo.Service.TechSearchSerive" />
155
+
156
+ <mvc:annotation-driven />
157
+
158
+ <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
159
+ <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
160
+ <property name="prefix" value="/WEB-INF/view/"/>
161
+ <property name="suffix" value=".jsp"/>
162
+ </bean>
163
+
164
+ </beans>
165
+ ```