Can someone point out whats wrong with below code snippet.
package com.hibernate.test;
import java.io.Serializable;
import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.Embedded; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;
@Entity @Table(name="MyOrder") public class MyOrder implements Serializable { @Column(name="orderId") @Id private Long orderId; @Access(AccessType.PROPERTY) @AttributeOverrides({ @AttributeOverride(name="street",column=@Column(name="billingstreet")), @AttributeOverride(name="zipcode",column=@Column(name="billingzip")), @AttributeOverride(name="city",column=@Column(name="billingcity")) }) @Embedded private Address address;
/** * @param orderId * @param address */ public MyOrder(Long orderId) { super(); this.orderId = orderId; }
/** * */ public MyOrder() { super(); // TODO Auto-generated constructor stub }
public Long getOrderId() { return orderId; }
public void setOrderId(Long orderId) { this.orderId = orderId; } public Address getAddress() { return address; } public void setAddress(Address address) { this.address = address; }
} package com.hibernate.test;
import java.io.Serializable;
import javax.persistence.Access; import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Embeddable;
@Embeddable @Access(AccessType.PROPERTY) public class Address implements Serializable{ @Column(name = "street") private String street; @Column(name = "zipcode") private String zipcode; @Column(name = "city") private String city; /** * */ public Address() { super(); // TODO Auto-generated constructor stub } /** * @param street * @param zipcode * @param city */ public Address(String street, String zipcode, String city) { super(); this.street = street; this.zipcode = zipcode; this.city = city; }
public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public String getZipcode() { return zipcode; } public void setZipcode(String zipcode) { this.zipcode = zipcode; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } } @Test @Rollback(false) @Transactional public void testSaveMyOrder() throws Exception { Session session = sessionFactory.getCurrentSession(); MyOrder order = new MyOrder(); order.setOrderId(Long.valueOf(1)); Address add = new Address(); add.setCity("testlocation"); add.setStreet("avenue"); add.setZipcode("9408"); order.setAddress(add); session.save(add); session.flush(); }
using Mysql 5,5, Getting below org.hibernate.MappingException: Unknown entity: com.hibernate.test.Address,on running JUnit. 5971 [main] INFO org.springframework.test.context.transaction.TransactionalTestExecutionListener - Committed transaction after test execution for test context [[TestContext@49275b5e testClass = OrderPersistenceTests, testInstance = com.hibernate.test.OrderPersistenceTests@36df9dd7, testMethod = testSaveMyOrder@OrderPersistenceTests, testException = org.hibernate.MappingException: Unknown entity: com.hibernate.test.Address, mergedContextConfiguration = [MergedContextConfiguration@12f3aa66 testClass = OrderPersistenceTests, locations = '{classpath:/com/hibernate/test/OrderPersistenceTests-context.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]]
|