0

フォーム付きのシンプルな Web ページがあります。値を挿入して db に送信します (addPage.html addPageController catalogDAo)。CatalogDAO でメソッドを永続化するまでは、すべて問題ありません。データは db に挿入されません (mysql、eclipselink、jpa。IDE - STS Eclipse)。Google とフォーラムからのアドバイスを試しましたが、うまくいきませんでした。エラーはありません。ページは正常にロードされていますが、持続しません。何が起こっているのかわかりません。誰かが同じ問題を抱えていますか?ありがとう!ここに私のコードがあります:
servlet-context.xml

      <?xml version="1.0" encoding="UTF-8"?>
     <beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="foo" />
<annotation-driven />
<resources mapping="/css/**" location="/css/" />
<resources mapping="/js/libs/**" location="/js/libs/" />
<resources mapping="/img/**" location="/img/" />
    <beans:bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <beans:property name="defaultLocale" value="en_US" />
</beans:bean>
<beans:bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
    <beans:property name="paramName" value="language" />
</beans:bean>
<beans:bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
    <beans:property name="interceptors">
       <beans:list>
        <beans:ref bean="localeChangeInterceptor" />
       </beans:list>
    </beans:property>
</beans:bean>
<beans:bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <beans:property name="basename" value="locale/messages" />
</beans:bean>
<beans:bean id="templateResolver"
    class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    <beans:property name="prefix" value="/web-inf/views/" />
    <beans:property name="suffix" value=".html" />
    <beans:property name="templateMode" value="HTML5" />
</beans:bean>
<beans:bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
    <beans:property name="templateResolver" ref="templateResolver" />
</beans:bean>
<beans:bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
    <beans:property name="templateEngine" ref="templateEngine" />
</beans:bean>
<beans:bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <beans:property name="url" value="jdbc:mysql://localhost:3306/katalog" />
    <beans:property name="username" value="root" />
    <beans:property name="password" value="1977" />
</beans:bean>
    <beans:bean id="emf"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <beans:property name="persistenceUnitName" value="eCommerce" />
</beans:bean>
<tx:annotation-driven/>
   </beans:beans>


persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="eCommerce">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>foo.components.Catalog</class>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/katalog"/>
  <property name="javax.persistence.jdbc.password" value="1977"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
  <property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>


ダオ

@Component
@Transactional(propagation = Propagation.SUPPORTS)
public class CatalogDAO {
@PersistenceContext private EntityManager em;

public void zapisz(Catalog strona) {
 em.persist(strona);
      }
public Catalog getStrone(int Id){
    return em.find(Catalog.class, Id);
}
public List<Catalog> getAllStrony() {
    TypedQuery<Catalog> query = em.createQuery(
       "SELECT c FROM Catalog c ORDER BY c.id", Catalog.class);
    return query.getResultList();

}

エンティティ
_

  @Entity
  @Table(name="catalog")
  @NamedQuery(name="Catalog.findAll", query="SELECT c FROM Catalog c")
  public class Catalog implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="Id", unique=true)

private long Id;

private String adres;

private String opis;

private String tytul;

public Catalog() {
}

public long getId() {
    return this.Id;
}

public void setId(long Id) {
    this.Id = Id;
}

public String getAdres() {
    return this.adres;
}

public void setAdres(String adres) {
    this.adres = adres;
}

public String getOpis() {
    return this.opis;
}

public void setOpis(String opis) {
    this.opis = opis;
}

public String getTytul() {
    return this.tytul;
}

public void setTytul(String tytul) {
    this.tytul = tytul;
}
4

2 に答える 2