alluchandrasekhar wrote:Thanks phillip,
Now i understood , but i did not find any Hibernate annotation plain query in our demo source code. and I have 2 questions ?
1) how can we created new entities , extending entities I know from docs site, but newly create tables how ?
2) I am working demo site and admin modules. If today I created two users through register form, then we can see in the those users details in admin- Customer table. but tomorrow the data will lose why it will happened. How it works exactly. Now i did not connect any data base. please explain me. any default database are there like derby in Ofbiz/opentaps ?
Thanks in advanced
Chandu allu
(Im using package/folder interchangably)
Whatever your package is... lets say its com.mycompany.mymod
Add a folder "domain" add an interface name it MyMod that extends from serializable (import java.io.Serializable;) now you declare all your getters and setters
ie
Code: Select all
public interface Slider extends Serializable{
public Long getId();
public void setId(Long id);
public String getTitle();
public void setTitle(String title);
public String getDescription();
public void setDescription(String description);
etc
Then make a new class "MyModImpl" that implements MyMod interface
ie:
Code: Select all
@Entity
@Table(name="BLC_MYMOD")
public class MyModImpl implements MyMod {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "MyModId", strategy = GenerationType.TABLE)
@TableGenerator(name = "MyModId", table="SEQUENCE_GENERATOR", pkColumnName = "ID_NAME", valueColumnName = "ID_VAL", pkColumnValue = "MyModImpl", allocationSize = 1)
@Column(name = "MYMOD_ID")
private Long id;
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
@Column(name="TITLE")
private String title;
@Override
public String getTitle() {
return title;
}
@Override
public void setTitle(String title) {
this.title = title;
}
Make sure you add the appropiate values to the sequence generator it needs to know the name and the starting value.
Under your webapp/WEB-INF (Or they go under resources? Some some modules do it one way or another so why not both) you should add a few xml files like this here's a sample from my work in progress:
File named bl-slider-applicationContext.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="org.broadleafcommerce.slider" />
<bean id="blMergedEntityContexts" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>classpath:bl-slider-applicationContext-entity.xml</value>
</list>
</property>
</bean>
<bean id="blMergedPersistenceXmlLocations" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>classpath*:/META-INF/persistence-slider.xml</value>
</list>
</property>
</bean>
</beans>
bl-slider-applicationContext-entity.xml
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="org.broadleafcommerce.slider.domain.Slider" class="org.broadleafcommerce.slider.domain.SliderImpl" scope="prototype" />
</beans>
Then in your web.xml of site or admin modules look fors:
Code: Select all
<context-param>
<param-name>patchConfigLocation</param-name>
<param-value>
.....
</param-value>
</context-param>
and add: classpath:/mymod-applicationContext.xml
Answer to question 2 since it's in development mode it will regenerate the tables every time you redeploy. Each module has a runtime-properties under it all derive from the core module ie: common-shared.properties which gets overidden by what ever the application deployment context is. What you're most likely looking for is under site modules development.properties blPU.hibernate.hbm2ddl.auto