Deep Clone Of Entities - Set Primary Keys To Null
Nov 21, 2014
I need to get a clone of a fairly deep object tree. All objects are entities and I need to set the primary keys to null. The root object:
public class Grundentscheidung implements Cloneable {
@OneToMany(cascade = CascadeType.ALL)
@JoinColumns({
@JoinColumn(name = "gesamtentscheidung_dstNr"),
@JoinColumn(name = "gesamtentscheidung_id")
[Code] .....
When I call
Grundentscheidung grundentscheidungClone = grundentscheidung.clone();
grundentscheidungClone contains the whole object tree with all dependencies, but the Tatbestand objects have their primary keys. When I use the debugger I see that Tatbestand.clone() is never called.
Is my code faulty? I would like to avoid to write a large method which sets all primary keys on the object tree to null.
View Replies
ADVERTISEMENT
Oct 22, 2010
I am new with java, eclipse, jpa(eclipselink), postgresql, and trying to make a web application. I have two tables:
bids: id, quantity, price
trades: bidid, askid, quantity, price
bidid and askid columns are foreign keys from bids table (id), and they are the primary key for the trades table.
I created the Entities from the Tables (Bid and Trade class) with eclipse and it generated a TradePK class for the primary key.
Trade.java:
@Entity
@Table(name="trades")
public class Trade implements Serializable {
@EmbeddedId
private TradePK id;
[Code] ....
I understand that this is necessary because the primary key is from two column, but as soon I want to persist a Trade back to the database Eclipselink call the column names twice:
INSERT INTO trades (price, quantity, datetime, BIDID, ASKID, bidid, askid) VALUES (?, ?, ?, ?, ?, ?, ?)
So postgres give me back an exception: ERROR: column "bidid" specified more than once
And I don't know why. According to the JPA docs I didn't found any mistake:
Introduction to EclipseLink JPA (ELUG) - Eclipsepedia
Or I just can't see it... or is there a better doc which explains it better?
View Replies
View Related
Mar 21, 2014
how to do a deep copy of objects that contain references. I am specifically wanting to make a deep copy of a tree. Logically, each tree node contain references to its children nodes. Here is the basics of my node class
public class BSTNode implements Comparable, Serializable {
private String token;
private int count;
private BSTNode leftChild;
private BSTNode rightChild;
I know I must only be making a shallow copy because when I make a copy of tree1, called tree2, and edit tree1 the edits also appear on tree2. Here is my copy method within my BSTNode class
public BSTNode copy()
{
BSTNode obj = null;
try{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(this);
out.flush();
out.close();
[code]....
When I wish to copy the entire tree, I call that above copy method from my BSTree class using the methods below. (I have 2 methods because this is a homework assignment that requires a copy method that calls a preorder traversal method)
public BSTNode copy()
{
BSTNode copiedTreeRoot = new BSTNode();
return copyTree(copiedTreeRoot,root);
[code]....
And further along when I make changes to tree1, tree 2 also changes. I have no clue what I'm doing wrong. I believe it must be somewhere in how I return the new tree or something.I tried this edit to my copy method, but it made no difference.
public BSTNode copy() {
BSTNode obj = null;
try{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(this);
[code].....
View Replies
View Related
Oct 31, 2014
The company entity contains companyName, Sector and Segment columns. The mapping is 3 entities (Company, Sector, Segment) where Sector and Segment are used to create a company record. Sector has a OneToMany relationship with Segment and with Company. I put the Sector and Segment values into two select menus as use these to create a Sector and Segment reference for the Company table. I'm getting the following exception:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row:
a foreign key constraint fails (`testdummy`.`company`, CONSTRAINT `FK_COMPANY_FK_COMPANY_SECTORID` FOREIGN KEY
(`FK_COMPANY_SECTORID`) REFERENCES `sectors` (`SECTORID`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
I'm thinking that the problem is that since the Segment entity is a child of Sector it must be entered through an instance of Sector. Because it's being entered as a separate value I'm getting this error. The problem is Segment is defined as a Set in the Sector entity and I can't figure out how to declare Segment as an instance using its parent entity (Sector).
My code is as follows, starting with the Sector entity:
@Entity
@Table(name = "SECTORSNEW")
public class SectorsNew {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int sectorId;
private String sectorName;
@OneToMany(cascade = CascadeType.PERSIST)
[code]....
View Replies
View Related
Apr 10, 2015
I would like to create list of entities which is populated by a search function with the data coming from our REST webservice. However I would like it to be multi-line, with the first line being details from the entity itself and the second line buttons for options that can be performed.
So as an example say my entity is People, the first line would contain columns for first name, last name, gender, DOB, etc. The second line would be buttons for "Edit Person", "Print Person details". With the standard TableView I can't see anyway to alternate between one row of data and another row of buttons.
View Replies
View Related
May 29, 2014
How do you do validation in java for primary key lets say the table got combination of two columns as primary key,how can i validate that if use enter already existing value...
View Replies
View Related
May 30, 2014
i have a table with two columns as primary key i what to trap exception if the use in UI try to enter duplication in the table i don't what to throw ORA ERROR i what to display meaningful error massage,my database is oracle 11g
this is how i what to do it
i what to add integrity constraint to the table, and i use explicitly name it.
- i test the database to figure out what exception it returns for that constraint. With luck the name i used will be in the text of the exception.
- i add a catch to my database layer that catches SQLException, looks for the error message, and then throws a different exception, probably my own message
- In my UI layer catch that specific exception and convert it to something appropriate.
View Replies
View Related
Mar 26, 2015
i need to design an application by java that is capable of coping itself and put it somewhere else.
and i have tried ....
import java.io.*;
import java.nio.*;
public class Test1234{
[Code]....
but it just create an empty folder named "test.class" but i need the overall class file or jar file.
View Replies
View Related
Jan 20, 2015
I thought numeric literal were by default int or doubles, depending on if have a . and numbers after the But I wrote a quick test program as listed below. I understand the float float floatA = 5.5; failed to compile since 5.5 is a literal of type double and you are trying to assign this to a floag
What I am having problems with is byte byteA = 5; 5 is a literal of type int and this is being assigned to a byte and compiler should complain.The compiler does not allow two byte values to be added and assigned to a byte since the result of the addition is an int
class literalTesting{
public static void main(String[] arg){
byte byteA = 5; // allowed WHY I thought literal is an int and assigning int to byte
byte byteB = 10; // allowed
[code]...
View Replies
View Related
Jun 20, 2014
I want to clone some Arraylist, but the compiler apparently are just referencing the values to it's original ArrayList. I don't know what should it be:
package projetoteste;
import java.util.ArrayList;
import java.util.List;
public class TestFood {
public static void main(String[] args) {
List food=new ArrayList();
[code]....
Notice that ArrayList dailyMeal should be untouchable, but it return the changes that I made in local for-loop iteration although I didn't added nothing to it, just to it's clone.
Output:
[[[Suco, 1 , 2], [Suco, 1 , 2]], [[Suco, 1 , 2], [Suco, 1 , 2]]]
[[[►, ►, Suco, 1 , 2], [►, ►, Suco, 1 , 2]], [[►, ►, Suco, 1 , 2], [►, ►, Suco, 1 , 2]]]
View Replies
View Related
May 14, 2014
the clone method of the object class is protected, so therefore we have to override this method I understand this. What doesn't make sense to me is that the protected access modifier gives access to classes in the same package and subclasses. Isn't every single class we make a subclass of the Object Class?
View Replies
View Related
Nov 10, 2014
My question is, how do I get my Cube to visualize in the JPanel? I've tried a bunch of add methods but they don't compile. Is there a proper method I can use to add an object to a JPanel?
import javax.swing.*;
import java.awt.Dimension;
import javax.swing.Timer;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;
[Code] ....
View Replies
View Related
Feb 21, 2015
I am currently working on a Minecraft clone (called "Build"), and I'm trying draw just ONE simple dirt block, but it will only draw a square!
Here is the main class:
package game;
import game.block.DirtBlock;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
[Code] ....
And the Block class ( the one that all Block Types are based off of):
package game;
import static org.lwjgl.opengl.GL11.*;
import java.io.IOException;
import java.nio.FloatBuffer;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
[Code] ....
And that is the code, I'll make updates as needed.
View Replies
View Related
Apr 16, 2014
I'm getting an error on line 137 and all it is rsmd = rs.getMetaData();The error happens only after I press a JButton and it is
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionat softwareDesign.createAccount.actionPerformed(createAccount.java:137)
There is a lot more to it but that has nothing to do with my code it's just the stuff with Eclipse anyway I want to know how do I fix this problem?
View Replies
View Related
Feb 28, 2015
public class Test {
public static void main(String[] args) {
Car c = new Car();
c.setInf("toyota", "red");
System.out.println("name: "+ c.brand + " colour: " + c.colour);
[code]....
Why do I get the result brand null, colour null? I know what null means but what am I missing here?
View Replies
View Related
Apr 5, 2014
I am asked in my assignment to make a program that accepts a text file as an example a novel and i have to sort each word as a PERSON or ORGANIZATION or LOCATION or O as in Other , example :
Microsoft/ORGANIZATION ,/O Nelly/PERSON !/O '/O
Now we notice that microsoft is and organitzation and "," is Other and Nelly is a person's name and so on ..
Now I am asked to return the numbers of tags in the text which is 4 in our case because we have (ORGANIZATION,PERSON,LOCATION,OTHER)
My question here is my logic true ? And since i made a map of String,String ; Is there any way that i can get the size of the values in our case the values are the organization etc.. ?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
[code].....
View Replies
View Related
Feb 9, 2014
I have one doubt.In HashMap if keys contains 1,2,3,4 and values are a,b,c,d we can get values using get(key) method like 1 will A,2 will return B and so on. Can we get the keys from values like A will get 1 and also if in key if there is a String like 1,2,3,Z and value is A,B,C,7 Z should get me 7. Here I am not using any generics.
View Replies
View Related
Jul 14, 2014
I am writing a code that tries to figure out the users password by going through every possible key (brute force). Although I think its going to work, it looks EXTREMELY inefficient to me, since its just a huge switch statement for each character -- 94 total, including the shift values. Is there a built in method in the JAVA API that goes through every key or something?
Here is my code for that segment:
public char[] HackingPassword(){
char[] passChars = this.password.toCharArray();//convert the password to char[]
char[] hacking = new char[passChars.length];//make the hacking variable same size as users password
int nextCharValue = 0;//this is used to cycle through the keyboard
//check each letter of hacking to match with password
for(int i = 0; i < passChars.length; i++){
[Code] .....
View Replies
View Related
Jul 4, 2014
I want to write a method to print the all the names of a phone book. phoneBook is a HashMap<String, String> , that has names as keys and phone numbers as values.
Reading the documentation for both HashMap and Set, I have more or less an idea of how it could be done but I cant put it on code..
public String getName()
{
String[] keys = phoneBook.keySet().toArray();
return keys[0];
}
This is wrong. It doesnt compile saying incompatible types. I was thinking first to manage to succeed to get a key from my phone book and then I change it to print all the keys.
View Replies
View Related
Aug 12, 2014
I am trying to work with a SQL database and some JSF pages that were created with/for CRUD. The data comes up just fine but all my foreign keys show the primary key for the key not the data. So instead of having the actual Zone I get the number (my primary key) that matches the Zone.
example:
4717A Cool ReceptionTitle: Gatherer of Cool Companycom.vancowboy.lotor_db.LotroZones[ id=11 ]
The last item should read "All" not "com.vancowboy.lotor_db.LotroZones[ id=11 ]"
This was straight from a tutorial so I can learn this but the FK has got me baffled...
View Replies
View Related
Dec 21, 2014
I have the following hashMap declared:
private HashMap<String, Car> cars = new HashMap<String, Car>();
How can i get an array of String filled with hashMap keys?
View Replies
View Related
Apr 22, 2014
I'm learning Java using BlueJ, I have made a class that has a HashMap of (String, String) that contains an the make of a car and the model.
I want a method to return a collection of all the keys that satisfy a condition, like if someone wants to find what make a certain model is. I know it requires a loop, just not too sure how to write the loop to satisfy the condition.
View Replies
View Related
Apr 9, 2014
I Want to identify up, down, left and right keys with the keylistener() WHATE NAME DO I IDENTIFY IT WITH
View Replies
View Related
Dec 13, 2014
Here is my HashMap and a method for listing all the keys in it
HashMap<String, String> exampleOne = new HashMap<String, String>();
public void allKeys() {
int i;
i =0;
for (String name: exampleOne.keySet())
[Code]....
Now I want to return all values that associated with one key. How do I do this? Or is it possible to other way round? I mean return All keys associated with a value?
View Replies
View Related
Aug 27, 2014
I am developing a java code using netbeans for encryption decryption by RSA algorithm. Swings and file handling play a major role in these code. My encryption code is working nicely but the code for decryption is not since keys file is not being read. That is why variable mod and pri are getting null values and the following error stack is coming. I know where the problem is somewhere in void readkeys() function but cannot solve it.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.math.BigInteger.modPow(BigInteger.java:1579)
at rsakeydecryption1.RsaKeyDecryption.decryption(RsaKeyDecryption1.java:167)
at rsakeydecryption1.RsaKeyDecryption.read_output(RsaKeyDecryption1.java:294)
at rsakeydecryption1.RsaKeyDecryption.actionPerformed(RsaKeyDecryption1.java:330)
[Code] .....
My code for decryption is
package rsakeydecryption1;
import java.math.BigInteger;
import java.util.Random;
import java.io.*;
import javax.swing.*;
[Code] ....
View Replies
View Related
Mar 15, 2014
Suppose that a certain BST has keys that are integers between 1 and 10, and we search for 5. Which sequence below cannot be the sequence of keys examined?
(a) 10,9,8,7,6,5
(b) 4,10, 8, 6, 5
(c)1,10,2,9,3,8,4,7,6,5
(d) 2,7,3,8,4,5
(e)1,2,10,4,8,5
I've noticed many differences, such as there is only one with an odd number of keys, and one has all integers from 1-10 inside of it, but I can't find any real reason that you wouldn't be able to search it?
View Replies
View Related