hibernate-mapping

Hibernate Creating Unwanted Mapping Tables

℡╲_俬逩灬. 提交于 2019-12-07 05:12:26
I am creating a schema. My schema is as follows @Entity @Table(name = "PROMOTION") public class Promotion { @Id @Column (name = "promotion_id") private String promotionId; @JoinColumn(name = "seller_id") private List<Seller> sellerList; }; @Entity @Table(name = "SELLER") public class Seller { @Id @Column (name = "seller_id") private String sellerId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "promotion_id") private Promotion promotion; @ManyToMany(fetch = FetchType.LAZY) @JoinColumn(name = "seller_id", referencedColumnName = "seller_id") private List<SellerPromotion> sellerList; };

One to many hibernate join if column names are different

廉价感情. 提交于 2019-12-07 04:20:39
问题 I have three tables with following structure - Contract -> contract_id(primary), customer_company_id, Vendor_company_id Company -> Company_id(primary), creation_date, created_by Company_Timeline -> Timeline_id(Primary), Company_id, Company_name. and have following classes for these tables - Contract.java @Table(name = "CONTRACT") @Entity @SequenceGenerator(name = "ContractSeq", sequenceName = "SEQCONTRACT", allocationSize = 1) public class Contract implements Serializable { private static

Overriding @Id defined in a @MappedSuperclass with JPA

爷,独闯天下 提交于 2019-12-07 03:30:34
问题 I have a class AbstractEntity that is extended by all the entities in my application and basically acts as an Identifier provider. @MappedSuperclass public class AbstractEntity implements DomainEntity { private static final long serialVersionUID = 1L; /** This object's id */ @Id @GeneratedValue(strategy = GenerationType.AUTO) protected long id; @Temporal(TemporalType.TIMESTAMP) @Column(name="creation_date", nullable = false, updatable=false) private Date creationDate = new Date(); /** *

One to many cascade All is not setting parent id while child entry insertion

℡╲_俬逩灬. 提交于 2019-12-07 02:02:29
I am using Hibernate 3 annotations. I have a table 'product' and child table 'product_spec' with one-to-many relation. When i do hibernateTemplate.save(product) it is giving error could not insert: [com.xx.ProductSpec]; SQL [insert into Products_spec Column 'PRODUCT_ID' cannot be null @Entity @Table(name = "product") public class Product implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name = "PRODUCT_ID") private Integer productId; @Column(name = "PRODUCT_NAME") private String productName; @OneToMany(mappedBy = "product",fetch = FetchType

Hibernate EmptyInterceptor onFlushDirty() is not executing

▼魔方 西西 提交于 2019-12-06 15:42:41
I want to do Audit for my entity updates. So I have implemented EmptyInterceptor . My onFlushDirty() method is not executing, but afterTransactionCompletion() does executes I'm using Spring 4.1 and Hibernate 5.0 + I have not done any configuration rather than @Component in configuration file till afterTransactionCompletion() get executed. What I'm missing here ? Also how to intercept Event query.executeUpdate() ? My Interceptor class is as follows: @Component public class AuditLogInterceptor extends EmptyInterceptor { private static final long serialVersionUID = 1L; @Override public boolean

Hibernate unidirectional OneToMany delete violates constraint ( optional=false at parent side?)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 12:25:04
问题 I use Hibernate 3.6 and I have something like this: @Entity public class Parent { @OnyToMany( fetch = FetchType.LAZY, cascade = { ascadeType.ALL } ) @Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE ) @JoinColumn( name="Parent_ID" ) public List<Child> getChildren() { return children; } public void setChildren( List<Child> children ) { this.children = children; } private transient List<TitleMetadataCategory> children; ... } @Entity

Hibernate:Difference between setting the Id directly in the bean or calling the load() or get() method?

我的未来我决定 提交于 2019-12-06 12:04:01
Following is an example of load:- Stock stock = (Stock)session.load(Stock.class, new Integer(2)); StockTransaction stockTransactions = new StockTransaction(); //set stockTransactions detail stockTransactions.setStock(stock); session.save(stockTransactions); What is the difference if i directely set the id in like:- Stock stock =new Stock(); stock.setId(2); StockTransaction stockTransactions = new StockTransaction(); //set stockTransactions detail stockTransactions.setStock(stock); session.save(stockTransactions); As i already know the Id of the stock table. Y call the load or get? What is the

Map a composite key inside a composite key hibernate xml

▼魔方 西西 提交于 2019-12-06 11:56:46
问题 This is what I would like to do, map an object to another table that has the same primary keys. The below is an example, basically I have one object with a composite key that has a composite key for ANOTHER table, but I don't know how to include both in order to create the proper object key. I highlighted the row that is wrong, it only includes one of the properties for the key. <class name="BusinessRuleObject" table="BUSINESS_RULE_OBJECTS" schema="DB"> <composite-id name=

No Dialect mapping for JDBC type: -9 with Hibernate 4 and SQL Server 2012

爷,独闯天下 提交于 2019-12-06 11:24:49
I am using the latest Hibernate 4.2.7.SP1 along with the entity-manager, and validator, etc. I am using he Microsoft SQL Server 2012. The code I am trying to use is: StringBuffer sb = new StringBuffer(); sb.append("SELECT vr.account_name as account FROM MY_VIEW_RECEIVABLES vr;"); String sql = sb.toString(); System.out.println("MyInvoiceDAO: getInvoices: SQL=" + sql); SQLQuery q = this.sessionFactory.getCurrentSession().createSQLQuery(sql); q.addScalar("account"); q.setResultTransformer(Transformers.aliasToBean(InvoiceDTO.class)); List results = q.list(); FYI: MY_VIEW_RECEIVABLES is a view, and

How to retrieve a member object of a class using Hibernate?

我的未来我决定 提交于 2019-12-06 08:03:49
问题 Using following code I can successfully retrieve address fields of a user, to do that I need to define all its fields using Projection. Imagine address has 100 fields, in this case I have to define all of them. I am wondering if I can return just address object of customer without defining all its fields in Proposition? I know I can retrieve id of address and use that to retrieve its object, but I am wondering if there is ano other method rather than this or defining all its fields. Hibernate