How to insert a record which has a forgien key using Hibernate?
Dear all,
I have two Tables called User, Location. User has a foreign key "location_id" which is the primary key of Location.
The Location has already a record with location_id = 1.
Now I want to insert a new record to User table by Hibernate as follows:
Session session= this.getSession(); Location location = new Location(); location.setLocationId(new Long(1)); User user = new User(); user.setUserAccount("userAccount"); user.setFirstName("firstName"); user.setLastName("lastName"); user.setLocation(location); session.save(user);
The new record was inserted. But the column "location_id" is null (not 1 as I expected).
Could you tell me what is wrong?
Regards.
Pengyou
pengyou wrote:
Dear all,
I have two Tables called User, Location. User has a foreign key "location_id" which is the primary key of Location.
Is it mapped as 1:1? Is it bi-directional?
The Location has already a record with location_id = 1.
Now I want to insert a new record to User table by Hibernate as follows:
Session session= this.getSession();
Location location = new Location();
location.setLocationId(new Long(1));Hibernate sets that, not you.
User user = new User();
user.setUserAccount("userAccount");
user.setFirstName("firstName");
user.setLastName("lastName");
user.setLocation(location);
session.save(user);
The new record was inserted. But the column "location_id" is null (not 1 as I expected).
Could you tell me what is wrong? Hard to tell without your mapping .hbm.xml. But you don't set the ID, Hibernate manages that.
Similar Messages
-
How to get the records which has a specified x/y coordinates
Hi,
How to get the records which has a specified x/y coordinates. I have a table which has street data. And another table has a point data. Now I just want to get the records from street data which includes the points in the point data table. Can any one give your suggestions
Thanks and Regards
AravindanAravinda,
If you want to find the line segments which intersect the given
set of points, you can do that with SDO_RELATE.
siva -
How to insert null record (some col) in table using loop
Hi,
How to insert null record (for some columns) in table using loop.
sample data of x_tab
order_id order_name
231 xxx
123
345
111 vvvv
Thanks,
Lakshman
Edited by: kolipaka on Jul 5, 2012 1:37 PMYou have a table
CREATE TABLE tab (
col1 NUMBER,
col2 NUMBER,
col3 NUMBER,
col4 NUMBER
col5 NUMBER)Now you insert:
INSERT INTO tab (col2, col4) VALUES (5, 7);col1, col3 and col5 are NULL by default (there is no DEFAULT clause for these columns so they are NULL). -
Urgent help : how when insert new record navigation off
hi master
Sir
when i insert new record by mistake press down key and curser move to next record and my need is
When I insert new record or change any record that time my form navigation musht be off and no move to next record how I restrict to navigation please give me idea which event and what code I use
Thanking you
aamirIf u want the cursor not to move ahead from a particular field when the records are inserted or updated on that field then u can just write null to the
key-next-item trigger of that particular item.
ie IN key-next-item
null;
Hope this is what you wanted. -
How to insert multiple records in a single query
Dear all,
Can you please tell
how to insert multiple records in a single query ??INSERT INTO table_name (column_1, column_2) VALUES ('value_A', 'value_B')OR
INSERT INTO table_name
(column_1, column_2)
SELECT 'value_A', 'value_B' FROM DUAL
UNION ALL
SELECT 'value_C', 'value_D' FROM DUAL
;Edited by: Benton on Nov 9, 2010 1:59 PM -
How to insert a record in ROOSPRMSC table? (accidentally deleted)
Calling an InfoPackage in BW causes short dump, while fixing the short dump issue, accidentally
deleted the "ROOSPRMSC" table entries.
Could you tell me how to insert a record in "ROOSPRMSC" table???Hi Senthil,
Regards,
Phani Raj Kallur
Message was edited by: Phani Raj Kallur -
How to handle user preference which has "_" and " " in the name
Hi Experts,
I have a question how to handle value which has like "_" and "space" etc in user preference.
If setting "a_b-c d", I could not retrieve this because it's escaped in database.
So this code can't get value even though I can set it.
Is there any restriction of name? Is there any documentation how to code user prefernece which has non alphabet and number in the name?
I know it's possible to handle the data like adding escaped data. But I don't think this is the best way to retrieve the data. Because nobody confirm it's not problem in the future.
Could you tell me the best way to get these user preference?
Thanks in advance,
Masaaki Tada
Here is a sample.
<%@ page contentType="text/html;charset=Shift_JIS" %><%@ page language="java" import="com.plumtree.remote.portlet.*, com.plumtree.remote.prc.*, java.util.*" %>
<%
/** * UserInfo - Simple Page * Display User Information*/
// VariablesIPortletContext oPortletContext = null;IPortletRequest oPortletRequest = null;IPortletUser oPortletUser = null;IPortletResponse oPortletResponse = null;IRemoteSession s;IUserManager oUser;
/* Get Portlet Objects */
try{oPortletContext = PortletContextFactory.createPortletContext(request, response);oPortletRequest = oPortletContext.getRequest();oPortletUser = oPortletContext.getUser();oPortletResponse = oPortletContext.getResponse();} catch (Exception e) {oPortletContext = null;oPortletRequest = null;oPortletUser = null;oPortletResponse = null;}
String val = oPortletRequest.getSettingValue( SettingType.User, "a_b-c d" );String hoe = oPortletRequest.getSettingValue( SettingType.User, "abcd" );out.println( "a_b-c d: " + val );out.println( "abcd : " + hoe );
oPortletResponse.setSettingValue( SettingType.User, "a_b-c d", "aiueo" );oPortletResponse.setSettingValue( SettingType.User, "abcd", "bbbb" );%>Plumtree recommends that user preference names have only alphanumeric characters in them (a-z, A-Z, 0-9). Any non-alphanumeric characters will be encoded by the EDK.
I strongly suggest that you change your user pref name to something that's alphanumeric. However, if that is not possible, you can use the following workaround: in the web service editor, enter the encoded name for the user pref. There are several ways to get the encoded name.
One way is to encode the pref manually, yourself. Plumtree uses the %u encoded format: each non alphanumeric character is converted into %uxxxx, where xxxx is the Unicode representation of the character. For all ASCII characters, just look at the ASCII hex chart. For example, character "-" has a hex value of 2d. So, a preference name "jane_pref" would be encoded to "jane%u002dpref", and you'd enter the latter value on the preferences page in the web service editor.
The other way to find out the encoded value is to set a preference programmatically and use the HTTP tunnel tool to look at HTTP traffic between the portal server and remote server. The remote server will be sending a HTTP header to the portal server (the header name will probably be CSP-User-Pref) and inside the header you should see the pref name, encoded with %u. Just copy it out of there and into the web service editor.
Hope this helps,
Jane -
How to open the period which has already closed in MM
How to open the period which has already closed in MM.
1. Lock all users out of PRD
2. Take snapshot of MB5L for all materials at company code for current and previous periods
3. Add User parameter MMPI_READ_NOTE with value = current date in this format YYYYMMDD
4. Stop all processing that updates inventory values
5. Run t-code MMPI with correct period
6. Run Z_DEl_HIST_ENTRIES program
7. Take MB5L snapshot for all materials at company code fs01 for current and previous periods
8. Validate that values match on MB5L pre-post snapshots or are appropriate.
9. Unlock all users in PRD
10. Remove User parameter MMPI_READ_NOTE from user ID
chander -
How to insert past record after updating the master table in history table through store PROC
Master Table
Party Status
A Active
B Inactive
C Active
D Inactive
Duplicate Table
Party Status
A Active
B Active
C Active
D Inactive
Updated Master Table
Party Status
A Active
B Active
C Active
D Inactive
Party History Table
B Inactive
I have two table one master and another duplicate I need to update master table based on duplicate table insert the record which updated into Party history table as shown above. need help to write store proc.Check MERGE syntax in BOL (example D). There should be a sample with output, e.g.
insert into PartyHistory (Party, [Status])
select Party, [Status] FROM
(MERGE Master M using Duplicate D on M.[Party]=D.[Party]AND M.[Status]<>D.[Status]
WHEN MATCHED THEN UPDATE
SET [Status] = D.[Status]
OUTPUT Deleted.[Party], Deleted.[Status], $Action) AS Changes (Party, [Status], Action) WHERE Action = 'UPDATE'
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
How to Insert a record in a database table in debugging mode in production
Hi,
How to Insert a record in a database table in debugging mode in production ?
Waiting for kind response.
Best Regards,
Padhy
Moderator Message : Duplicate post locked.
Moderator message : Warning. Don't create multiple threads for same question.
Edited by: Vinod Kumar on May 12, 2011 11:02 AM
Edited by: Vinod Kumar on May 12, 2011 11:04 AMHi Senthil,
Regards,
Phani Raj Kallur
Message was edited by: Phani Raj Kallur -
How to upload a file which has more than 999 line item through BDC ?
Hello Techards
Hi to all
Can any body tell me how to upload a file which has more than 999 line item through BDC for traction F-02 ?
Thanks in advance.
ShovanHello Shovan,
You split it up to post two accounting documents with the help of a "suspense" a/c.
Say, you have to post the following line items below:
line 1 - dr. - GL a/c X - $1000
line 2 - cr. - GL a/c Y - $1
line 3 - cr. - GL a/c Y - $1
line 1001 - cr. - GL a/c Y - $1
You cannot post the above as a single doc in SAP (because of technical reasons), so you need to break it up into 2 documents as below:
Doc1
line 1 - dr - GL a/c X - $1000
line 2 - cr - GL a/c Y - $1
line 3 - cr - GL a/c Y - $1
line 998 - cr - GL a/c Y - $1
line 999 - cr - SUSPENSE a/c - $3
Doc2
line 1 - dr - SUSPENSE a/c - $3
line 2 - cr - GL a/c Y - $3
Note that there is no incorrect impact on accounting as first we credit suspense a/c by $3 and next we debit the same suspense a/c by $3 as a result the effect is nil. Similarly, we credit $997 to GL a/c Y (which is less by $3) in the first doc which is compensated by the second doc by crediting the shortfall of $3.
Hope this helps,
Cheers,
Sougata. -
How to clear the node which has multiple attributes
Hello ,
how to clear the node which has multiple attributes.
I've tried this using the method SET_STATIC_ATTRIBUTES_NULL but it's not working.
Thanks,
Sandhya.Hello,
I suggest you to create an internal table or structure clear it and the bind it to the context node.
Another possibility is to try to invalidate the node (method INVALIDATE of interface IF_WD_CONTEXT_NODE).
Regards. -
How Can insert the records into Excel_sheet by using SQL Task-SSIS ?
As per requirement ,
insert the records in excel sheet(DT) by using SQL Task-SSIS .
I used SQL query in SQL Task-SSIS:
e.g.., INSERT INTO [DT$B1:B1] VALUES ('COMMM')
but error:Executing the query "INSERT INTO [DT$B1:B1] VALUES ('COMMM') " failed with the following error: "This table contains cells that are outside the range of cells defined in this spreadsheet.". Possible failure reasons: Problems
with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Please any suggestion ...
-MADHUthen first create a table inside Excel sheet based on your source data. You can Execute sql task for that using excel connection. then use insert to populate it
see an example here where I create a dynamic sheet using execute sql task
http://visakhm.blogspot.in/2013/09/exporting-sqlserver-data-to-multiple.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to insert data from *.dmp file to oracle 11g using Oracle SQL Develope
hi
i backup my database using PL/SQL developer and made *.dmp file
how to insert data from *.dmp file to oracle 11g using Oracle SQL Developer 2.1.1.64
and how to make *.dmp file from sql*plus ?
thanks in advancePl/Sql developer has a config window, there you choose the exec to do the import/export.
Find it and his home version, it may be exp or expdp, the home version is the version of the client where the exp executable is.
Then use the same version of imp or impdp to execute the import, you do not need to use Oracle SQL Developer 2.1.1.64. If you want to use it, you must have the same version in the oracle home that exp/imp of sql developer use. -
How to insert a blank value in not nul column using transform activity
can anyone help me on how to insert blank values in a not null column using transform activity or however possible..This is a requirement in my project ..
vidya
In DB adapter or-mappings.xml , did you made any changes. If not the open that file in any notepad editor and change the following
<attribute-mapping xsi:type="direct-mapping">
<attribute-name>director</attribute-name>
<field table="MYTABLE" name="MAKE_IT_BLANK_NOT_NULL" xsi:type="column"/>
<attribute-classification>java.lang.String</attribute-classification>
</attribute-mapping>You can try to add this:
<attribute-mapping xsi:type="direct-mapping">
<attribute-name>director</attribute-name>
<field table="MYTABLE" name="MAKE_IT_BLANK_NOT_NULL" xsi:type="column"/>
<null-value></null-value>
<attribute-classification>java.lang.String</attribute-classification>
</attribute-mapping>Refer below link for details
Re: Insertion of Blank value to a Not Null varchar column in SQL server table
Thanks
AJ
Maybe you are looking for
-
Time capsule wifi working for Apple TV, but not my other 3 devices.
I recently moved. At my previous address, I had my Time Capsule creating a wifi network that all my devices connected to without a problem. Now, only my Apple TV connects. My MacBook Pro, iPhone, and iPad do not connect. They can see the network, b
-
Do I need to do anything different with the client or is it a server setting that needs modification
I have a Flex based application which is using Flash Media Server (FMS) server (version 4.0) for live video streaming between two users (i.e. a one to one teleconferencing service). This streaming is one-to-one, as defined by business rules, so that
-
Dhcpcd.service vs dhcpcd@eth0.service
Hello everybody, It seems like I have 2 dhcpcd services: dhcpcd.service and [email protected] The eth0.service one fails at boot, however the first one seems to work. systemctl status dhcpcd dhcpcd.service - dhcpcd on all interfaces Loaded: loaded
-
Hai.... how get swf width and height using loader ,we are getting different values .... // Fla document size is 550 X 400,but we are getting 500 X 375... <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
-
Converting MOV file to iTunes file
On my MacBook Pro, I have been converting MOV files to iTunes files. Suddenly, however, this won't work. I get the following message: Can't make file "Macintosh HD:private:var:folders:Al:AlJFXwbEEgqKI3EA0xH26 TI:-Tmp- How can I fix this?