在broadleaf中创建新实体

时间:2016-07-07 08:06:25

标签: entity-framework hibernate broadleaf-commerce

注意:我正在使用PostgreSQL数据库     在数据库中构建并运行表未创建之后     我为创建新实体的broadleaf文档做了同样的事情:

   1.  **Created new interface** :

package com.mycompany.entity.ordereturn;

 public interface OrderReturn {
        Long getId();
        void setId(Long id);
        String getReason();
        void setReason(String reason);
        String getAddress();
        void setAddress(String address);
    }
  1. 创建新的OrderReturnImpl类

    @Entity

    @Table(name =" blc_order_return")

    public class OrderReturnImpl implements OrderReturn{
    
    @Id
    @GeneratedValue(generator= "OrderReturnId")
    @GenericGenerator(
            name="OrderReturnId",
                        strategy="org.broadleafcommerce.common.persistence.IdOverrideTableGenerator",
            parameters = {
                @Parameter(name="segment_value", value="OrderReturnImpl"),
                @Parameter(name="entity_name", value="com.mycompany.entity.ordereturn.OrderReturnImpl")
            }
        )    
    
    @Column(name = "OrderReturn_ID")
    protected Long id;
    
    @Column(name = "Reason")
    protected String reason;
    
    @Column(name = "Address")
    protected String address;
    
    @Override
    public Long getId() {
        // TODO Auto-generated method stub
        return id;
    }
    
    @Override
    public void setId(Long id) {
        // TODO Auto-generated method stub
        this.id = id;
    }
    
    @Override
    public String getReason() {
        // TODO Auto-generated method stub
        return reason;
    }
    
    @Override
    public void setReason(String reason) {
        // TODO Auto-generated method stub
        this.reason = reason;
    }
    
    @Override
    public String getAddress() {
        // TODO Auto-generated method stub
        return address;
    }
    
    @Override
    public void setAddress(String address) {
        // TODO Auto-generated method stub
        this.address = address;
    }
    }
    
    1. 在persistence-core.xml文件中配置
    2.  <persistence-unit name="blPU" transaction-type="RESOURCE_LOCAL">
              // Added this line in name = "blPU"
                  <class>com.mycompany.controller.account.OrderReturnImpl</class>
                   <exclude-unlisted-classes/>
              </persistence-unit>
      

2 个答案:

答案 0 :(得分:0)

虽然您尚未发布完整的OrderReturnImpl.java文件,但您可能错过了@Entity注释(以及@Table注释)。

请相应地注释您的课程。

好的,我看到一个新的编辑,你现在有了注释。那么错误仍然会继续 这些注释?

如果要从实体创建数据库表,请使用 <property name="hibernate.hbm2ddl.auto">create</property>

答案 1 :(得分:0)

如果您在独立服务器上运行admin / site,则可能出现的问题是创建表。在嵌入式tomcat或jetty上试一试。

配置:

  • 在admin / resource / runtime-properties / development.properties
blPU.hibernate.hbm2ddl.auto=create
blCMSStorage.hibernate.hbm2ddl.auto=create
blSecurePU.hibernate.hbm2ddl.auto=create
  • 在core / resource / runtime-properties / common-shared.properties
blPU.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
blSecurePU.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
blCMSStorage.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
blPU.hibernate.hbm2ddl.import_files_sql_extractor=org.broadleafcommerce.common.util.sql.importsql.DemoPostgresSingleLineSqlCommandExtractor
blSecurePU.hibernate.hbm2ddl.import_files_sql_extractor=org.broadleafcommerce.common.util.sql.importsql.DemoPostgresSingleLineSqlCommandExtractor
blCMSStorage.hibernate.hbm2ddl.import_files_sql_extractor=org.broadleafcommerce.common.util.sql.importsql.DemoPostgresSingleLineSqlCommandExtractor
  • 使用您的数据填充的database.properties

一定要:

  • [standaloneserver] / lib中的PostgreSQL驱动程序或在嵌入式服务器上运行时作为库

  • 无效的IDE缓存

  • 在所有项目(或所有三个模块)上清理并安装maven目标

  • 在pom的执行和postgresql依赖中使用postgresql启动数据库

<plugin>
     <artifactId>maven-antrun-plugin</artifactId>
     <version>1.8</version>
          <executions>
               <execution>
                    <id>postgres-start</id>
                    <configuration>
                         <target>
                              <echo message="Starting postgres database..."/>
                              <java fork="true" spawn="true" classname="org.postgresql.Driver"
                                      classpathref="maven.plugin.classpath">
                              </java>
                              <echo message="Database started successfully"/>
                         </target>
                     </configuration>
                     <goals>
                         <goal>run</goal>
                     </goals>
                 </execution>
              </executions>
              <dependencies>
                  <dependency>
                      <groupId>org.postgresql</groupId>
                      <artifactId>postgresql</artifactId>
                      <version>9.4.1211</version>
                  </dependency>
              </dependencies>