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.
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:
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 {
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);
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)
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.
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...
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.
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
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.
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?
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?
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?
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.. ?
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.
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++){
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..
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.
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...
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.
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?
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)
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?
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?