From 2d66576b920a23ef4d42c2219ddbd0252ca236bc Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 7 Jul 2005 03:35:22 +0000 Subject: [PATCH] completed insert select support git-svn-id: https://svn.jboss.org/repos/hibernate/trunk/Hibernate3/doc@7396 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- reference/en/modules/batch.xml | 43 +++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/reference/en/modules/batch.xml b/reference/en/modules/batch.xml index ef26155bcc..197cb6ae89 100755 --- a/reference/en/modules/batch.xml +++ b/reference/en/modules/batch.xml @@ -95,7 +95,7 @@ session.close();]]> - + DML-style operations @@ -188,7 +188,7 @@ session.close();]]> The psuedo-syntax for INSERT statements is: - INSERT INTO EntityName (properties_list)? select_statement. Some + INSERT INTO EntityName properties_list select_statement. Some points to note: @@ -198,18 +198,15 @@ session.close();]]> Only the INSERT INTO ... SELECT ... form is supported; not the INSERT INTO ... VALUES ... form. - The properties_list is optional. It is analogous to the column speficiation - in the SQL INSERT statement. If omitted, all "eligible" (see next) properties are - automatically included. + The properties_list is analogous to the column speficiation + in the SQL INSERT statement. For entities involved in mapped + inheritence, only properties directly defined on that given class-level can be + used in the properties_list. Superclass properties are not allowed; and subclass + properties do not make sense. In other words, INSERT + statements are inherently non-polymorphic. - - For entities involved in mapped inheritence, only properties directly defined on that - given class-level can be used in the properties_list. Superclass properties are not - allowed; and subclass properties do not make sense. In other words, INSERT - statements are inherently non-polymorphic. - select_statement can be any valid HQL select query, with the caveat that the return types must match the types expected by the insert. Currently, this is checked during query @@ -221,6 +218,30 @@ session.close();]]> database might not make a distinction or might be able to handle the conversion. + + + For the id property, the insert statement gives you two options. You can either + explicitly specify the id property in the properties_list (in which case its value + is taken from the corresponding select expression) or omit it from the properties_list + (in which case a generated value is used). This later option is only available when + using id generators that operate in the database; attempting to use this option with + any "in memory" type generators will cause an exception during parsing. Note that + for the purposes of this discussion, in-database generators are considered to be + org.hibernate.id.SequenceGenerator (and its subclasses) and + any implementors of org.hibernate.id.PostInsertIdentifierGenerator. + The most notable exception here is org.hibernate.id.TableHiLoGenerator, + which cannot be used because it does not expose a selectable way to get its values. + + + + + For properties mapped as either version or timestamp, + the insert statement gives you two options. You can either specify the property in the + properties_list (in which case its value is taken from the corresponding select expressions) + or omit it from the properties_list (in which case the seed value defined + by the org.hibernate.type.VersionType is used). + +