Shariq Roomi

Ranch Hand
+ Follow
since Oct 19, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Shariq Roomi

I migrated from 3.3 to 3.5.1 and I am hitting



My code has


Any idea what is going on

Thanks,
Thanks Mark for your reply. The schema is sample to demonstrate the problem.
I did some research and was able to see the multiple columns for joining which you are telling me.

In teacher class, I did

@OneToMany(cascade = {CascadeType.ALL})
@JoinColumns ( {@JoinColumn(nullable=false, name="teacher_id"),
@JoinColumn(nullable=false, name="teacher_name")})
private List<Student> student;

and in student class, I did

@ManyToOne (fetch=FetchType.EAGER, cascade = {CascadeType.ALL})
@JoinColumns ( {@JoinColumn(nullable=false, name="teacher_id",
updatable=false, insertable=false),
@JoinColumn(nullable=false, name="teacher_name",
updatable=false, insertable=false)})
private Teacher teacher;

But then I got following exception

org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of PK.id; nested exception is org.hibernate.PropertyAccessException: could not get a field value by reflection getter of PK.id
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of PK.id

at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:35)
at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:64)
at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:70)
at org.hibernate.tuple.component.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.java:83)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:353)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:348)
at org.hibernate.event.def.AbstractVisitor.processComponent(AbstractVisitor.java:82)
at org.hibernate.event.def.ReattachVisitor.processComponent(ReattachVisitor.java:43)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:107)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:268)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:21
7)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java
:93)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
I am getting the exception org.hibernate.AnnotationException: A Foreign key refering Teacher from Student has the wrong number of column. should be 2

The code is as follows. Can some one please help me with this code , what am I doing wrong ? :-( I have eliminated get/set from all classes

DB Schema:

Teacher(id,name)
Student(id , teacher_id, teacher_name)

@Entity
@Table(name="Teacher")

public class Teacher implements Serializable {

@EmbeddedId
private PK pk = new PK();

@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name="teacher_id")
private List<Student> student;

public List<Student> getStudent() {
return student;
}

public void setStudent(List<Student> student) {
this.student = student;
}
}


/////////////////////
@Entity
@Table(name="Student")

public class Student implements Serializable {

@Id
@Column(name="id")
private int id;

@ManyToOne
@JoinColumns ( {@JoinColumn(nullable=false, name="id"),
@JoinColumn(nullable=false, name="name")})
private Teacher teacher;
}

///////////////////////////
@Embeddable
public class PK implements Serializable
{
private int id;
private String name;
}
@Entity
@Table(name="Teacher")

public class Teacher implements Serializable {
@Id
@Column(name="id")
private int id;

@Column(name="name")
private String name;

@OneToMany
@JoinColumn(name="id")
private List<Student> student;

//getter/setters
}

/////////////////////////////

@Entity
@Table(name="Student")

public class Student implements Serializable {

@Id
@Column(name="id")
private int id;

@Column(name="stuname")
private String StudentName;

//getter/setters
}


And to store object, I am using

Teacher t1 = new Teacher();
t1.setId(10);
t1.setName("from hibernate");


Student s1 = new Student();
s1.setId(10);
s1.setStudentName("Student from hibernate");

List<Student> l = new ArrayList<Student>();
l.add(s1);

t1.setStudent(l);

getHibernateTemplate().save(t1);

The query generated by hibernate is

Hibernate: insert into Teacher (name, id) values (?, ?, ?)
Hibernate: update Student set id=? where id=?

Why am I getting update for student, this is a new object, Can any body please help me
I have simple pojos and I need to generate some other pojos based on them using annotation. Can some one please points me to some examples/resources.
17 years ago
Okay I figure out the issue but I have no solution.

If your service is implementing some interface then the parameters are named as param0 and param1 of functions from interface. It has nothing to do with debug option.

Is there any work around ??
17 years ago
Dudley, I am laso having the same issue with Axis2. I looked into sample apps of Axis2, they also have same problem. This wsdl is useless then as I can't asl client to use param0, param1 etc.Please share if you find any work around.


Arafat, this wsdl is generated by accessing localhost:8080.services.
17 years ago
Thanks Guys. If the server get compromized then we would have problem so this is the reason we do not wnat to keep password in plain text.
17 years ago
I have primary keys etc stored in java key store and I have hard coded the password for keystore for now but I am thinking to store that password in text file in encrypted form. The architect of my team does not want to store password for keystore in database so now I need two way hashing algo. to store password in text file and then read it back at server start.

Any idea from where I can get two way hashing algo in java ??

Or are there any other better means to store password for key store.
17 years ago
Thanks Jan but I want to do programmatically.

There is a function in KeySTore class

setKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
Assigns the given key to the given alias, protecting it with the given password.

So I am wondering hwo could I get the corresponding Certficate array for my privatekey ??
18 years ago
I can not simply make sense of this KeySTore Class.

I have private and public key and I simply want to use them in KeyStore to use later.

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN"); java.security.NoSuchProviderException
keyGen.initialize(512 , random);
KeyPair keypair = keyGen.genKeyPair();
PrivateKey priKey = keypair.getPrivate();
PublicKey pubKey = keypair.getPublic();


File f = new File("c:\keystore");
// Create an empty keystore object
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());

???
// code to store private and public key in keystore

// Save the new keystore contents
FileOutputStream out = new FileOutputStream(keystoreFile);
keystore.store(out, password.toCharArray());
out.close();


Can some one please help me with missing code.
18 years ago
I am writing a login method that will authencticate user and return token for web services. Next time user will send us token and we will validate the token but requirement is that we donot want to keep any state of token at server.What does it mean that when we receive token, we should be able to determine it is a valid token or not.(This implied token can't be forged by any user).

I have written a function using KeyPairGenerator, please have a look and let me know if you see any security issue.

Design is

token generateToken(userid) {
hash = hash(userid) ------------------- ONE
Signature = Encrypt (Private key , hash) --------------- TWO
return hash + " " + Signature
}

bool isValid(token) {
separate part 1 and part 2 of toekn (delimeter is space)
Signature = Encrypt (Public key , part1)
if signature == part2
token is valid
else
token is invalid
}


Code is

PublicKey privateKey ;
PrivateKey publicKey ;
KeyPairGenerator keyGen;
SecureRandom random ;
KeyPair keypair;

public String generateToken() throws Exception{

keyGen = KeyPairGenerator.getInstance("DSA");
random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(512 , random);
keypair = keyGen.genKeyPair();
privateKey = keypair.getPrivate();
publicKey = keypair.getPublic();

String token = userName;
byte[] part1 = getHash(1000, token , generateSalt());

/* Create a Signature object and initialize it with the private key */
Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
dsa.initSign(privateKey);

/* Update and sign the data */
dsa.update(part1, 0 , part1.length) ;

/* Generate a signature for it */
byte[] realSig = dsa.sign();

String tokenToReturn = byteToBase64(part1) + " " + byteToBase64(realSig) ;

return tokenToReturn;

}


public void verifyToken(String token) throws Exception{

int space = token.indexOf(" ");
String part1 = token.substring(0 , space);
String part2 = token.substring(space+1);

/* create a Signature object and initialize it with the public key */
Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
sig.initVerify(publicKey);

byte[] bPart1 = base64ToByte(part1);
byte[] bPart2 = base64ToByte(part2);

/* Update and sign the data */
sig.update(bPart1, 0 , bPart1.length) ;

if ( sig.verify(bPart2) )
System.out.println("signature verifies: " );
else
System.out.println("signature does not verifies: " );
}


Does this code look right ??? Please let me know if you see any pitfalls or know better way to create token
18 years ago
I am trying to create Salt fo my passwords. This is my function

public byte[] generateSalt() throws Exception{

random = SecureRandom.getInstance(SECURE_RANDOM_ALGORITHM);
random.setSeed(System.currentTimeMillis());
byte[] salt = new byte[8];
random.nextBytes(salt);
return salt;

}

I called this function three times in my main method , I got follwing output

Salt is [B@7d772e
Salt is [B@11b86e7
Salt is [B@35ce36

I run my program again and got same output. Every time I run my program, I get same output. What is happening, I can't understand. I set seed current time so every time I should get different numbers.
18 years ago
I have hdk 1.4 as well as jdk 1.5 in my machine.

JAVA_HOME points to jdk 1.5

I need to compile my java code using jdk 1.4.

How could I specify in build.xml to use jdk1.4 for compiling my code?

Thanks
18 years ago
I am susin gnat and build id failin gwith following output

BUILD FAILED
E:\axis2-1.1.1\samples\quickstartxmlbeans\build.xml:78: java.util.zip.ZipException: The system cannot find the file specified

Now I really do not know why this exception is coming. can I get the stack trace from Ant ???
18 years ago