INSERT « Query « JPA Q&A





1. hibernate insert into select    stackoverflow.com

How can I generate insert statements like insert into table (sequence.nextval, 'b0) using hibernate? Hibernate currently selects the sequence.nextval value and only then it uses the value to insert the entry in ...

2. How to insert an "Optimizer hint" to Hibernate criteria api query    stackoverflow.com

i have a hibernate query that is dynamically put together using the criteria api. it generates queries that are unbearably slow, if executed as-is. but i have noted they are about 1000% faster ...

3. Hibernate, insert or update without select    stackoverflow.com

I have a products objects which belongs to certain categories i.e. classical many to one relationship.

@Entity
public class Product{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    ...

4. Hibernate - controlling Insert and Update Queries    stackoverflow.com

Consider the following association Book has OneToMany Chapters If i execute:

session.save(book)
session.save(chapter)
session.getTransaction().commit()
Hibernate generates insert query for Book and insert query for Chapter But if i execute:
session.save(chapter)
session.save(book)
session.getTransaction().commit()
Hibernate executes insert query for chapter, insert query for book ...

5. Hibernate query insert    stackoverflow.com

could we realize an insert query with hibernate. I read that must be a jdbc connection to the database if we want to insert into a table. think you.

6. Hibernate: how to maintain insertion order    stackoverflow.com

I have a list of entities where creation order is important, but they do not contain a timestamp to use for sorting. Entities are added to the end of the list ...

7. HQL: combine "insert into ... select" with fixed parameters values    stackoverflow.com

I have HQL statement:

insert into Item (ost, value, comments, startTime, endTime, proposedBy) 
select si.ost, si.value, si.comments, si.endTime, si.endTime, u 
from Item si, User u 
where si.ost = ? and u.id = ...

8. prevent insert while select query, hibernate    stackoverflow.com

new to hibernate. I have a problem that when i am trying to run select query say

"from Foo where Foo.some_id=2"
(with hibernate template) then hibernate is also tries to insert the records ...

9. Does hibernate preserve the order of a LinkedHashSet and if so, how?    stackoverflow.com

Does hibernate preserve the order of a LinkedHashSet and if so, how? In case this depends on the type of database, I'd like to know this for PostgreSQL. Background: I know what a ...





10. insert into .. select in HQL causes MismatchedTreeNodeException    stackoverflow.com

I'm trying to do what seems like a pretty straightforward insert into .. select with HQL, but I am stumped by a MismatchedTreeNodeException. As far as I can tell, I'm the ...

11. How to prevent unnecessary select on insert?    stackoverflow.com

I have the following scenario (in Java / Hibernate):

  • I have two entity classes: X and Y. X has a @ManyToOne association to Y which is not cascaded.
  • I create an (unmanaged) instance ...

12. Execute Insert and Select queries simultaneously from Hibernate    stackoverflow.com

I have the following pl/sql query,

INSERT INTO Table(ID,..................) 
VALUES(SEQ.nextval,....................); 
SELECT SEQ.currval ID FROM DUAL;
I need to get ID using hibernate. I am using the following query which showing error,
.....getDataSession().createSQLQuery(hQuery).list()
Any one help ...

13. Is there a Hibernate way to do MySQL "select insert(t.text,100,1000,'...') from myTable t;"?    stackoverflow.com

Is there a Hibernate way to what MySQL documents here? http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_insert Eg:
select insert(t.text,100,1000,'...') from myTable t; Basically I am trying to let Hibernate do my abridging of text for me, rather ...

14. problem in insert query in hibernate    coderanch.com

Hi, I am using Hibernate version:3.0 and oracle 10. In my method, first will execute 4 insert query. after executing all insert queries , finally it should be calling a procedure and commit the transaction. My problem is when i calling this method, what hibernate does is,first calling the procedure and then executing all insert queries. Why is it doing like ...

15. Querying after insert. second level cache is not storing    forum.hibernate.org

I am learning second level cache, It didn't work properly. Can anyone explain this please. Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); C c1 = new C(); c1.setName("c1"); session.saveOrUpdate(c1); session.getTransaction().commit(); session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); C test = (C)session.get(C.class, c1.getId()); // I expected to get this object from second level cache. But hibernate does a select a select. // Hibernate did ask the second ...

16. insert into ... select with Criteria API    forum.hibernate.org

Hello, I have used Criteria API for a fairly complex query that can return up to 1 million entries. Unfortunately i have to store this data in a table so i would need something like insert into ... select because iterating through such a large list and inserting one by one is a performance bottleneck. Can i find something similar in ...





17. Controlling Insert and Update Query ordering    forum.hibernate.org

19. Update/insert without select?    forum.hibernate.org

Hi, Is it possible with Hibernate (plain, or though JPA) to achieve following jdbc scenario - update something where id=x, if 0 records updated, then insert something. Just two queries. My problem is that when i do em.merge it first tries to select from db which is 'redundant' call. Probably some isolation, transaction settings? Best regards, Eugene.

20. Insert/Update executed in wrong order    forum.hibernate.org

Given Tabels A, B, C: Attributes table A: A_ID Attributes table B: B_ID A_ID --> Foreign Key C_ID --> Foreign Key Attributes table C: C_ID A_ID --> Foreign Key JPA Entities implementation: There is a bidirectional Relation between class B and A. The relation betwenn Class C and A is not mapped. There is only a @Column("A_ID") annotation in C on ...

21. Select causing insert?    forum.hibernate.org

Hi there, I'm facing a quite weird behavior of hibernate. This is what happens: right after the deployment of my application I try to log in with some of the registered users. When this is done, I can see in the logs that there is a INSERT statement being executed when there is no persist or merge calls in the code, ...

22. Tuning - 150+ inserts per second, 50+ selects per second    forum.hibernate.org

Hello, We have a data acquisition application with two primary modules interfacing with DB (via Hibernate) - one for writing the collected data into DB and one for reading/presenting the collected data from DB. Average rate of inserts is 150-200 per second, average rate of selects is 50-80 per second. Performance requirements for both writing/reading scenarios can be defined like this: ...

23. prevent insert while select query    forum.hibernate.org

public List getAllSnsUsersByProperty(String prop, Object val){ String query = "from SnsUser su where su." + prop + " =:" + prop; return executeQuery(query, new String[]{prop}, new Object[]{val}); } public ...

24. Update query is firing instead of Insert query    forum.hibernate.org

Hi, i have requirement where i need to display two records. here user can add more records by right clicking (using gwt ). user tries to remove those two records and adds one more record, then i need to delete 2 records and insert 1 record. i am passing 2 separate lists, one contains deleted rrecords, the other one contains inserted ...

25. Why does Hibernate SELECT before INSERT and UPDATE?    forum.hibernate.org

I am using Hibernate 3.6. I have a simple OneToOne mapping between NewUser and UserStatusType. Code: @Entity @Table( name = "USER" ) @org.hibernate.annotations.Entity( selectBeforeUpdate = false) public class NewUser extends AbstractTimestampEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name= "user_id") private Long userId; ...

26. update query is firing first then insert query    forum.hibernate.org

Hi, i have a requirement where first i need to insert list of records in to data base then i need to fire an update query to update some column's value of inserted records. but the problem is first it is firing update query and then insert query. how can prevent firing an update query first. for me insert query should ...

27. Select from one table and insert into another table    forum.hibernate.org

Hi, I will get a set of data from one table (select based on condition and having as list) and need to insert the data into another table. What is the best approach for doing this. Example: Table A ID GrpId Name Age 1 21 Test 22 2 21 Test1 23 Select from the above table A and insert into table ...

28. Is it possible to use insert with select subquery??    forum.hibernate.org

To whom it may concern, Is it possible to use the following sql synatx in Hibernate: Insert table1(x, y) select table2.v1, table3.v2 from table2, table3 where table2.id = table3.id and table2.v4 = 1 and table3.v5=2 If yes, how can I use hibernate to generate a sql query like the above?? If not, what is the alternative in Hibernate that I can ...

29. Why update Query is called; but i want insert    forum.hibernate.org

30. query cache not invalidated when doing INSERT with CMT    forum.hibernate.org

Author Message jasonf Post subject: query cache not invalidated when doing INSERT with CMT Posted: Tue Dec 21, 2004 11:38 pm Newbie Joined: Tue Dec 21, 2004 6:08 pm Posts: 6 Location: Sydney, NSW, Australia We are at the moment exploring caching with respect to Hibernate. The application is a collection of stateless session beans, exposed via RMI to ...

31. insert into ... select    forum.hibernate.org

How do I execute an "insert into [tablename] values ([fieldname1], [fieldname2], ...) select [field1], [field2], ... from [anotherTableName]" ? 1 ) HQL documentation chapter 11 only explains "select" syntax. 2 ) session.createSQLQuery "Can not issue data manipulation statements with executeQuery()" 3 ) I don't want to instantiate many objects and save them. For performance reasons, I prefer one massive SQL request. ...

33. How to controll the insert order    forum.hibernate.org

public void testAddChild() { NodeDAO ndao = new NodeDAO(); Node node = ndao.findByID(5); Node n1 = new Node("grade 1","grade"); Node n2 = new Node("grade 2","grade"); Node n3 = new Node("grade 3","grade"); node.addChildNode(n1); node.addChildNode(n2); node.addChildNode(n3); HibernateUtil.commitTransaction(); HibernateUtil.closeSession(); } mysql> select * from node; +----+---------+--------+----------------+ | ID | NAME | TYPE | PARENT_NODE_ID | +----+---------+--------+----------------+ | 5 | myschool| school | NULL | ...

34. Tries to select when I want to insert (help)    forum.hibernate.org

Hi guys, the relationship is One to many bidirectional Destino -> Ligacoes Pessoa -> Ligacoes Funcionario-> Ligacoes i am trying to persist a new Ligacao (in english means "phonecall" or "call") to a Destino(destiny), Pessoa(People) , Funcionario already persisted. But it is selecting Ligacao opposite to Insert in sql LOG. Thank you very much and sorry by english. Hibernate version:2.1.7 Mapping ...

35. unsaved transient instance - inserts in wrong order    forum.hibernate.org

Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message elenamas Post subject: unsaved transient instance - inserts in wrong order Posted: Wed Feb 16, 2005 12:01 pm Newbie Joined: Thu Dec 09, 2004 12:29 pm Posts: 10 Hi I have a problem with what appears ...

36. Problem in insert query    forum.hibernate.org

Hibernate Version : v2.1 I am having some problem while executing the insert query through hibernate. Let me give you an overview about my work around. Please refer to the model attached for data model w.r.t physical data model. Here LoanPartyRole is the representation of Mapping table called "LOAN_PARTY_MAPPING" which have references from PARTY, HOME_LOAN and PARTY_TYPE. Then PARTY has references ...

37. influence order in which hibernate performs inserts / update    forum.hibernate.org

Hi, is there a way to influence the order in which hibernate (3.0.5) performs the insert and update statements ? Problem is that i have a Business object that has a list of security objects. I load the business objects, modify them and the associated security objects. After that i save the business objects. For some reasons hibernate performs an insert ...

38. 'select' before 'insert' and 'insert' after 'update'    forum.hibernate.org

Beginner Joined: Tue Jul 12, 2005 11:15 am Posts: 29 Hi, I don't understand why hibernate needs: - to make a select SQL command before inserting the data, - to make an update SQL command after inserting the data. ____________ | Car | ------------------ | id | |fatherCar | |firstSonCar | |nextSiblingCar | ------------------ I intialize the first car, the second ...

39. Problem using INSERT INTO ... SELECT    forum.hibernate.org

Hi! I tried to use the INSERT INTO ... SELECT statement. The fellowing SQL is sent to the database (Oracle): insert into dummy2.RiskAssignment ( Version, RiskAssignmentID, RiskGroupID, RiskVirtualAssetID ) select ?, dummy2.hibernate_sequence.nextval, riskgroup1_.RiskGroupID as RiskGrou1_146_0_, virtualass0_.RiskVirtualAssetID as RiskVirt1_148_1_, riskgroup1_.Version as Version146_0_, riskgroup1_.Name as Name146_0_, riskgroup1_.Description as Descript4_146_0_, riskgroup1_.Priority as Priority146_0_, riskgroup1_.ConsiderAbsoluteLimit as Consider6_146_0_, riskgroup1_.LimitAbsolute as LimitAbs7_146_0_, riskgroup1_.ConsiderPercentageLimit as Consider8_146_0_, riskgroup1_.LimitPercentage as ...

40. unwanted insert on a query AND legitimate uses of evict?    forum.hibernate.org

I am sorry that this is so vague, but perhaps someone here can help. I am using Spring and Hibernate 3 in a web application. I need to perform a query on the database. The Hibernate session is managing a dirty object that corresponds to a row in the table being queried. I do not want Hibernate to update the table ...

41. INSERT INTO ... SELECT FROM ...    forum.hibernate.org

42. query cache and insert="false" update="false    forum.hibernate.org

Hi I found a problem with query cache and insert="false" update="false" atributes. When object is retreived from cache, some properties are null, but when object is loaded directly from db everything is ok. Hibernate version: Hibernate 3.1.2 Mapping documents: ...

43. Problem with insert into ...select query - ambiguous column    forum.hibernate.org

Hi, I am using Hibernate 3.1.1 and annotations beta 8. I am trying to do an insert into select, but I am getting abiguous columns. There is a cross join in my select and it is ignoring the reference to the second table, but the query works fine in oracle. Here is an example HQL query insert into c (id, a, ...

44. Query cache and insert    forum.hibernate.org

I have the following simple method: public static void main(String[] args) { HibernateUtil.beginTransaction(); Session session; session = HibernateUtil.getCurrentSession(); for (int i = 0; i <10; i++) { Person person = new Person(); person.setNickName( "test" + i ); session.saveOrUpdate( person ); List list = session.createCriteria( Person.class ) .add(Restrictions.eq( "nickName", "homer" )) .setCacheable(true) .list(); } HibernateUtil.rollbackTransaction(); HibernateUtil.closeSession(); } This makes the query cache ...

45. Insert wz Select    forum.hibernate.org

46. How to change ordering of insert queries    forum.hibernate.org

Is is possible to change the way Hibernate orders the queries when doing inserts? I have a list of chocolates and a list of boxes that hold the chocolates, and would like to insert all of the chocolates before the boxes into the database in order to avoid constraint issues. I'm encountering an issue where it looks like hibernate is inserting ...

47. Problem doing an insert select where selecting from 2 tables    forum.hibernate.org

The hql i'm trying to execute is as follows: insert into AssetAttribute(asset, libraryAssetAttribute, version) select ASS, LAA, 0 from Asset ASS, LibraryAssetAttribute LAA where ASS.libraryAsset = LAA.libraryAsset and ASS.libraryAsset.assetType.id = 961 The problem as shown below in the stack trace is that in 'ASS.libraryAsset = LAA.libraryAsset' this gets converted into 'library_asset_id=library_asset_id ' with no reference to the containing objects, and so ...

48. Select called on an insert    forum.hibernate.org

For some reason whenever I insert a new object by calling Session.save() (using either String, Object or Object) Hibernate does a select first. The select does not use the unique ID for the table and this select takes quite some time to return causing the save to be very slow. The object is defined with a java.lang.Interger ID field and the ...

49. Select, Insert, Updates    forum.hibernate.org

Hi Everyone: I am using Spring 2.0 and Hibernate 3.1. I am seeing "Select" statements when inserting a row into the database using Hibernate. After the insert, I see an update to the database. Is this normal? If not what can I do to tune it so it just does an insert. Any suggestions to tune Hibernate so that it does ...

50. how do you create updates and inserts in in native queries    forum.hibernate.org

do you have to add a native query to an entity as follows and how do you do update inserts and deletes in native quesries in hibernate Query query = session.createSQLQuery(sql).addScalar("stdErr",Hibernate.DOUBLE). addScalar("mean",Hibernate.DOUBLE); //Double [] amount = (Double []) query.uniqueResult(); Object [] amount = (Object []) query.uniqueResult(); System.out.println("mean amount: " + amount[0]); System.out.println("stdErr amount: " + amount[1]) List insurance = session.createSQLQuery("select {ins.*} ...

51. need to run a native SQL Insert as a named query    forum.hibernate.org

I made my Insert query (which is native SQL) as a named sql query and when I ran it using int records = SQLQuery .executeUpdate(); I got a following Exception java.lang.UnsupportedOperationException: Update queries only supported through HQL at org.hibernate.impl.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:753) at com.fanniemae.fapt.mtm.domain.ref.common.TopMoversMappingLoader.main(TopMoversMappingLoader.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) Also if I try to put the query in tag , than how ...

52. Inserts not done in topological order...    forum.hibernate.org

Hi All, I'm having troubles when persisting entities tightly related. I have three entities: ActiveItem public class ActiveItem extends Entity { @ManyToOne(cascade = {CascadeType.ALL}) @JoinColumn(name = "logicalitemid") private LogicalItem logicalItem; ... } LogicalItem public final class LogicalItem extends Entity { @OneToMany(mappedBy = "logicalItem", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) private Set activeItems = new HashSet(); @OneToOne(fetch = FetchType.LAZY, mappedBy = "logicalItem", ...

53. Select for multiple values and to Insert    forum.hibernate.org

public class MyInterceptor extends EmptyInterceptor { @Override public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) { Session session = HibernateUtil.currentSession() ; X audit = new X() ; // audit table Y y ; // entity being saved if (entity instanceof Y) { y = (Y) entity ; audit.setId(y.getId()) ; session.save(y) ; } return super.onSave(entity, id, state, propertyNames, ...

54. Hibernate Insert order    forum.hibernate.org

55. Problem with many-to-many and insert query    forum.hibernate.org

Newbie Joined: Sat May 05, 2007 4:19 pm Posts: 5 Hi I have some problems with my many-to-many association. I'm using Hibebernate 3 and Spring 2. I have a table person, a table language and a table persons_languages In my java object, I have a class Person which has a set of Language and a class Language which has a set ...

57. Does Hibernate 3.0 support Native SQL: INSERT...SUB SELECT    forum.hibernate.org

Hi, I m using Hibernate 3.0. I m using fully HSQL for processing data but I need to use Native SQL for preprocess with considering the huge data need to be processed. I tried to use session().createSQLQuery(sqlString) to perform Selecting From one table and inserting into new table in one sql statement (sqlString) sqlString has been tested working fine under normal ...

58. insert ff by an update Query on using CompositeUserType    forum.hibernate.org

I observed that on using CompositeUserType, when I save an object which contains the property defined by CompositeUserType, the SQLs generated are an insert statement followed by an update statement with only the fields in CompositeUserType. My application is very sensitive to the SQLs generated as there are triggers on update statements and this results in a pseudo update in my ...

59. Hibernate selecting, but not inserting ... but not always.    forum.hibernate.org

Hi, I am finding that when I execute my code one way, Hibernate works fine. But when I execute it slightly differently, Hibernate will never execute any insert SQLs. I'll try and explain .... I should probably make it clear up front that I am using the Spring framework, and it could be something at this level causing the problem. Now, ...

60. INSERT INTO...SELECT problem    forum.hibernate.org

61. Insert from SELECT with subquery using HQL    forum.hibernate.org

Newbie Joined: Fri Jun 30, 2006 7:00 pm Posts: 6 I'm attempting to do a batch insert from a query using HQL. However, I'm not getting the results I expect. Here's the HQL query I'm attempting to use: Code: return session.createQuery("insert into ListingUrl (campaignUrl, listingTarget) " + ...

62. Insert order gotcha    forum.hibernate.org

A little trick with insert order that might be interesting to some. Inserts are normally done in the order that objects are added to the persistence context. However, cascading can "promote" an insertion to earlier than you might think. Say I have: A --> C B --> C Where --> is a cascading one-to-many relationship. C is obviously a join table. ...

63. insert query Vs call procedure.    forum.hibernate.org

Hi, I am using Hibernate version:3.0 and oracle 10. In my method, first will execute 4 insert query. after executing all insert queries , finally it should be calling a procedure and commit the transaction. My problem is when i calling this method, what hibernate does is,first calling the procedure and then executing all insert queries. Why is it doing like ...

64. insert select new query in hql    forum.hibernate.org

Hoi guys, I try to make the description of my problem as short as possible: In sql I have: insert into table_A ( select property_1, property_2, property_3 from table_B where condition ) This runs perfectly. property_n are fields of table_A. Let's say in hql table_A is represented by object_A and table_B by object_B. object_A has a composite key made out of ...

65. select-before-insert CascadeType.ALL    forum.hibernate.org

66. "Top 2" inserted in my native query    forum.hibernate.org

67. Hibernate applies select query before inserting an Object    forum.hibernate.org

Hi Hibernate applies select query before inserting an Object into DB. I.e. I have an object of ClassC, which has list of ClassD objects. Then I have an Object of ClassA and Object of ClassB, which share common object ClassC, Now I have two problem 1) First when I store an Object of ClassC, so along with inserting instance of ClassC ...

68. HQL insert into...select    forum.hibernate.org

Hi! I'm trying to duplicate entries of a table into same table resetting a field (ie duplicate redors of ITEM table setting a new value for ITEM_TYPE) I try this: Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); String sqlH ="insert into Item(name, description, item_type Select i.name, i.description, :newItemType from Item i where i.itemType=:oldItemType"; q = s.createQuery(sqlH); q.setParameter("newItemType ", newType); q.setParameter("oldItemType", ...

69. HQL is appending # symbol to table name in insert query    forum.hibernate.org

I am using JOINED subclass strategy. While generating insert statement, hibernate is generating an insert statement that contains # symbol appended to the table name as below: Hibernate: insert into #Configuration select config0_.Id as Id from Configuration config0_ where Id from Configuration config0_ where Id in (select config1_.Id from Configuration config1_ where config1_.TemplId in (?)) Because of this i am getting ...

70. Insert query in hibernate    forum.hibernate.org

Hi I wanted to know the rows affected so that I can put a condition so that the user can know that the values are stored into the database without any problem. Can I assume that if Hibernate does not give me an exception, the values are saved into the database and the row is affected? accordingly, I can code the ...

71. Setting order_inserts with JMX MBean    forum.hibernate.org

I would like to set the configuration options order_inserts and order_updates to true, as I have batch inserts that aren't getting rewritten by Mysql because they alternate between two different entities. The HibernateMBean doesn't seem to have an interface for setting these options. I am using hibernate 3.3.1 with JBoss 4.2.3. My setup uses the the hibernate-service.xml file to configure the ...

72. Order of Insert Objects    forum.hibernate.org

Hi, I have a strange problem with Hibernate. The first time around that I create some new objects and append it to an existing child relationship, all is well, and all is saved to the DB without any problems. I then create another new set of objects, which go through the exact same piece of code, and it attempts to write ...

73. Getting update/insert queries and not excute on db    forum.hibernate.org

Hi I just wanted to know if it possible to get a query that would be executed instead actually executing the query. The reason for tying to do this is that for transactions executed on the database, I actually need to store the sql that was executed for that transaction. Any help would be greatly appreciated.