Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Repeated column in mapping for entity

 
Tijo Mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to do an application in JPA with hibernate. But i am getting Repeated column in mapping for entity exception in my code. Please help me to correct if i am wrong in my code.

RegisterBean.java

public class RegisterBean
{
private String userName,password;

private long userID;
private Date dob;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="home_street")),
@AttributeOverride(name="state",column=@Column(name="home_state")),
@AttributeOverride(name="houseNo",column=@Column(name="home_houseNo"))
})
private AddressClass homeAddressClass;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street",column=@Column(name="office_street")),
@AttributeOverride(name="state",column=@Column(name="office_state")),
@AttributeOverride(name="houseNo",column=@Column(name="office_houseNo"))
})
private AddressClass officeAddressClass;



@Id
@Column(name="user_id")
@GeneratedValue(strategy=GenerationType.AUTO)

public long getUserID()
{
return userID;
}

public void setUserID(long userID)
{
this.userID = userID;
}
@Temporal(TemporalType.TIMESTAMP)
public Date getDob() {
return dob;
}

public void setDob(Date dob) {
this.dob = dob;
}
@Column(name="user_name")

public String getUserName()
{
return userName;
}

public void setUserName(String userName)
{
this.userName = userName;
}

public String getPassword()
{
return password;
}

public void setPassword(String password)
{
this.password = password;
}

public AddressClass getHomeAddressClass() {
return homeAddressClass;
}

public void setHomeAddressClass(AddressClass homeAddressClass) {
this.homeAddressClass = homeAddressClass;
}

public AddressClass getOfficeAddressClass() {
return officeAddressClass;
}

public void setOfficeAddressClass(AddressClass officeAddressClass) {
this.officeAddressClass = officeAddressClass;
}

}

AddressClass.java

@Embeddable
public class AddressClass
{
@Column(name="office_street")
private String street;
@Column(name="office_state")
private String state;
@Column(name="office_houseNo")
private Long houseNo;

public String getStreet()
{
return street;
}
public void setStreet(String street)
{
this.street = street;
}

public String getState()
{
return state;
}
public void setState(String state)
{
this.state = state;
}

public Long getHouseNo()
{
return houseNo;
}
public void setHouseNo(Long houseNo)
{
this.houseNo = houseNo;
}

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>


<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/shop</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1000</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<!-- <property name="current_session_context_class">thread</property> -->

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping class="com.all.RegisterBean" />

</session-factory>
</hibernate-configuration>

mainClass.java

public class HibernateCall
{
public static void main(String[] args)
{
RegisterBean registerBean=new RegisterBean();
AddressClass homeAddressClass=new AddressClass();
AddressClass officeAddressClass=new AddressClass();

registerBean.setUserName("t");
registerBean.setPassword("ti");
registerBean.setDob(new Date());
homeAddressClass.setStreet("tho");
homeAddressClass.setState("ke");
homeAddressClass.setHouseNo(13L);
registerBean.setHomeAddressClass(homeAddressClass);
officeAddressClass.setStreet("kot");
officeAddressClass.setState("k");
officeAddressClass.setHouseNo(14L);
registerBean.setOfficeAddressClass(officeAddressClass);
SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
Session session=sessionFactory.openSession();
session.beginTransaction();
session.save(registerBean);
session.getTransaction().commit();
session.close();


}

error is

Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: com.kjc.all.RegisterBean column: houseNo (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:681)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:703)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:699)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:725)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:478)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1294)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1736)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1782)
at com.all.MainClass.main(MainClass.java:28)

i checked with insertable=false and updatable=false. even it is not worked for me.

any help will be appreciatable. Thanks in advance
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic