Thanks Armin,
You were right, I have amended the typos I am not getting any Exception and I am making the objects persistent without problems.
At the moment everything is going OK, but I am sure I will find more problems.
Regards...
----- Original Message ----- From: "Armin Waibel" <[EMAIL PROTECTED]>
To: "OJB Users List" <[EMAIL PROTECTED]>
Sent: Monday, October 04, 2004 11:07 PM
Subject: Re: Mapping a simple class problem.
Hi Jose,
the exception says that UserBO does not declare at least one PK field.
> Caused by: > org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: OJB > needs at least one primary key attrib > ute for class objectsRealClass=class > com.jose.forum.businessobjects.UserBO,
In UserBO you set
> <field-descriptor > name="id" > column="id" > jdbc_type="INTEGER" > primaryKey="true" > autoincrement="true" > />
But primaryKey="true" is a typo and should be primarykey="true". By the way 'jdbc_type' should be 'jdbc-type' - another typo. Good luck!
regards, Armin
Jose Felix Hernandez wrote:
Hi,
I�m just getting started and this is my problem trying to map a single class. Find below the table structure, the BusinessObject java class, the repository.xml, the class I�m using to run the test and the exception I�m getting.
I hope somebody can help my to spot what is wrong...
Thanks...
The table structure is ...
CREATE TABLE `user` ( `id` int(11) NOT NULL default '0', `firstName` varchar(50) default NULL, `lastName` varchar(50) default NULL, `email` varchar(50) default NULL, `password` varchar(50) default NULL, `status` char(1) default NULL, PRIMARY KEY (`id`) ) TYPE=InnoDB ROW_FORMAT=DYNAMIC;
The BO is...
package com.jose.forum.businessobjects;
public class UserBO implements java.io.Serializable {
private int id; private String firstName; private String lastName; private String email; private String password; private String accountStatus;
//public UserBO(){ // super(); //}
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public String getEmail() { return email; }
public void setEmail(String email) { this.email = email; }
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
public String getAccountStatus() { return accountStatus; }
public void setAccountStatus(String accountStaturs) { this.accountStatus = accountStatus; } }
The repository-user.xml is...
<class-descriptor class="com.jose.forum.businessobjects.UserBO" table="user"
<field-descriptor name="id" column="id" jdbc_type="INTEGER" primaryKey="true" autoincrement="true" />
<field-descriptor name="firstName" column="firstName" jdbc-type="VARCHAR" />
<field-descriptor name="lastName" column="lastName" jdbc-type="VARCHAR" />
<field-descriptor name="email" column="email" jdbc-type="VARCHAR" />
<field-descriptor name="password" column="password" jdbc-type="VARCHAR" />
<field-descriptor name="accountStatus" column="status" jdbc-type="CHAR" /> </class-descriptor>
The class I�m using to test is...
public class Test {
static Implementation odmg = null; static Database db = null;
public static void main(String args[]) throws ODMGException{ UserBO user = new UserBO(); user.setId(0); user.setFirstName("Jose"); user.setLastName("Hernandez"); user.setEmail("[EMAIL PROTECTED]"); user.setPassword("jose"); user.setAccountStatus("A"); init(); Transaction tx = odmg.newTransaction(); tx.begin(); db.makePersistent(user); tx.commit(); destroy();
} private static void destroy() throws ODMGException{ db.close(); } private static void init() throws ODMGException{
ConnectionRepository cr = MetadataManager.getInstance().connectionRepository();
JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor(); jcd.setJcdAlias("jfhForum"); jcd.setUserName("web"); jcd.setPassWord("web"); jcd.setDbAlias("jfhForum"); jcd.setDbms("MySQL");
cr.addDescriptor(jcd);
PBKey key = new PBKey("jfhForum", "web", "web"); PersistenceBroker broker = PersistenceBrokerFactory. createPersistenceBroker(key);
odmg = OJB.getInstance(); db = odmg.newDatabase(); db.open("jfhForum", Database.OPEN_READ_WRITE);
} }
I get the below exception...
[org.apache.ojb.odmg.DatabaseImpl] ERROR: Persistence object failed:
[EMAIL PROTECTED]
Can not init Identity for given object
[EMAIL PROTECTED]
org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can not
init Identity for given object com.jose.foru
[EMAIL PROTECTED]
at org.apache.ojb.broker.Identity.init(Identity.java:157)
at org.apache.ojb.broker.Identity.<init>(Identity.java:114)
at
org.apache.ojb.odmg.locking.InMemoryLockMapImpl.getWriter(InMemoryLockMapImpl.java:64) at
org.apache.ojb.odmg.locking.AbstractLockStrategy.getWriter(AbstractLockStrategy.java:59) at
org.apache.ojb.odmg.locking.ReadUncommittedStrategy.writeLock(ReadUncommittedStrategy.java:60) at
org.apache.ojb.odmg.locking.LockManagerDefaultImpl.writeLock(LockManagerDefaultImpl.java:76) at
org.apache.ojb.odmg.TransactionImpl.lock(TransactionImpl.java:249)
at
org.apache.ojb.odmg.DatabaseImpl.makePersistent(DatabaseImpl.java:374)
at Test.main(Test.java:23)
Caused by:
org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: OJB
needs at least one primary key attrib
ute for class objectsRealClass=class com.jose.forum.businessobjects.UserBO,
objectTopLevelClass=class com.jose.forum.bu
sinessobjects.UserBO
at
org.apache.ojb.broker.Identity.checkForPrimaryKeys(Identity.java:277)
at org.apache.ojb.broker.Identity.init(Identity.java:153)
... 8 more
Exception in thread "main" org.odmg.ClassNotPersistenceCapableException: Can
not init Identity for given object com.jose
[EMAIL PROTECTED]
at
org.apache.ojb.odmg.DatabaseImpl.makePersistent(DatabaseImpl.java:385)
at Test.main(Test.java:23)
Thank you very much for your help.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
