How can I implement mysql replace into using hibernate? I couldn't find this anywhere.
-
Sorry i am not sure about the mysql replace, but can you elaborate more on whats your requirement? What is it that you want to do?ajay.patel– ajay.patel2013-06-17 15:30:30 +00:00Commented Jun 17, 2013 at 15:30
-
1in one of my project , I am having a number of update statements. it is taking so much time to execute. so I was planning to do a replace into instead of update. don't know how to do this through hibernate.Hrishi– Hrishi2013-06-17 15:41:38 +00:00Commented Jun 17, 2013 at 15:41
Add a comment
|
2 Answers
I believe, being an mySQL extension behavior, it's not supported directly. As normal for all unsupported query syntax's, you may want to use native SQL in this case.
Reference for native SQL support in hibernate, could be found here.
Comments
Actually you can use Hibernated named queries easily. You can either use Hibernate mapping files or Hibernate annotations in your entity class to get the job done.
Using mapping files.
<hibernate-mapping>
......
<sql-query name="yourNamedReplaceQuery">
<![CDATA[REPLACE INTO T SELECT * FROM T]]>
</sql-query>
</hibernate-mapping>
Using annotations
@NamedQueries({
@NamedNativeQuery(
name = "yourNamedReplaceQuery",
query = "REPLACE INTO T SELECT * FROM T"
)
})
@Entity
@Table(name = "your_object", catalog = "test")
public class YourObject implements java.io.Serializable {
Invoking the Named Query.
Query query = session.getNamedQuery("findStockByStockCodeNativeSQL");
More reference : http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql.html