You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Kanwar Manish <ka...@gmail.com> on 2012/07/05 14:46:34 UTC
Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Hi Guys
The statement inside the try block is causing the issue. At the end - code
from the object UserMaster is also copied.
if ((username!=null) && (!loggedIn))
{
DataContext dc = blgetcontext.getDatacontext();
logger.info(loginquery.toString());
List ls = dc.performQuery(loginquery);
if ((ls == null) || ls.isEmpty() || ls.size()<1)
result = true;
else
{
result = false;
this.currentuser = ((UserMaster)ls.get(0));
try
{
this.userid = this.currentuser.getUserMasterId();
}
catch(Exception ex)
{
String s = ex.getMessage();
}
}
}
Code for the UserMaster Object.....
public UUID getUserMasterId() {
return (UUID)readProperty("userMasterId");
}
Thanks for all the help.
Cheers
KM
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Andrus Adamchik <an...@objectstyle.org>.
Just moved it to "Custom types in PKs and relationships" thread. Let's discuss it there.
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Aristedes Maniatis <ar...@maniatis.org>.
Just as Andrus said: look at the lifecycle listeners.
Ari
On 21/07/12 2:27pm, Kanwar Manish wrote:
> Yes, this is a primary key column.
>
> If possible - please point me to an optimal way of initializing the column
> for new objects.
>
> On Fri, Jul 20, 2012 at 6:41 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
>>
>> On Jul 20, 2012, at 2:31 PM, Kanwar Manish wrote:
>>
>>> Column is of type varchar(36) in PostgreSQL and it is mapped as UUID in
>> the
>>> cayenne mapping.
>>
>> Is this a PK column?
>>
>>> In the constructor of the db class I am initiating the id.
>>> Values are being saved perfectly fine.
>>>
>>> "
>>> public class UserMaster extends _UserMaster {
>>>
>>> public UserMaster() {
>>> this.setUserMasterId(UUID.randomUUID());
>>> }
>>> .........}
>>
>> This is wrong, or at least suboptimal. Constructor is called not only when
>> a NEW object is created, but also when an existing one is selected from DB.
>> You need to use a different initialization mechanism, such as PostAdd
>> lifecycle callback or something like it. But this is an aside.. It doesn't
>> seem related to the issue.
>>
>> Andrus
>>
>>
>
--
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Kanwar Manish <ka...@gmail.com>.
Yes, this is a primary key column.
If possible - please point me to an optimal way of initializing the column
for new objects.
On Fri, Jul 20, 2012 at 6:41 PM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
> On Jul 20, 2012, at 2:31 PM, Kanwar Manish wrote:
>
> > Column is of type varchar(36) in PostgreSQL and it is mapped as UUID in
> the
> > cayenne mapping.
>
> Is this a PK column?
>
> > In the constructor of the db class I am initiating the id.
> > Values are being saved perfectly fine.
> >
> > "
> > public class UserMaster extends _UserMaster {
> >
> > public UserMaster() {
> > this.setUserMasterId(UUID.randomUUID());
> > }
> > .........}
>
> This is wrong, or at least suboptimal. Constructor is called not only when
> a NEW object is created, but also when an existing one is selected from DB.
> You need to use a different initialization mechanism, such as PostAdd
> lifecycle callback or something like it. But this is an aside.. It doesn't
> seem related to the issue.
>
> Andrus
>
>
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jul 20, 2012, at 2:31 PM, Kanwar Manish wrote:
> Column is of type varchar(36) in PostgreSQL and it is mapped as UUID in the
> cayenne mapping.
Is this a PK column?
> In the constructor of the db class I am initiating the id.
> Values are being saved perfectly fine.
>
> "
> public class UserMaster extends _UserMaster {
>
> public UserMaster() {
> this.setUserMasterId(UUID.randomUUID());
> }
> .........}
This is wrong, or at least suboptimal. Constructor is called not only when a NEW object is created, but also when an existing one is selected from DB. You need to use a different initialization mechanism, such as PostAdd lifecycle callback or something like it. But this is an aside.. It doesn't seem related to the issue.
Andrus
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Andrus Adamchik <an...@objectstyle.org>.
On Jul 20, 2012, at 3:00 PM, Kanwar Manish wrote:
> Just to add to this last statement of mine - why don't we have a type UUID
> available in the Cayenne modeller as data column type - for DbEntity?
Because DB types are based on JDBC spec, and it doesn't define UUID.
Andrus
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Kanwar Manish <ka...@gmail.com>.
Missing column type for DbEntity in Cayenne Modeller?
Just to add to this last statement of mine - why don't we have a type UUID
available in the Cayenne modeller as data column type - for DbEntity?
On Fri, Jul 20, 2012 at 5:01 PM, Kanwar Manish <ka...@gmail.com>wrote:
> Sorry guys. Exception wasn't being rethrown - so I thought it worked.
>
> Column is of type varchar(36) in PostgreSQL and it is mapped as UUID in
> the cayenne mapping. In the constructor of the db class I am initiating the
> id. Values are being saved perfectly fine.
>
> "
> public class UserMaster extends _UserMaster {
>
> public UserMaster() {
> this.setUserMasterId(UUID.randomUUID());
> }
> .........}
> "
>
> Any idea Andrus?
>
> Thanks
> KM
>
>
> On Thu, Jul 19, 2012 at 4:52 PM, Kanwar Manish <ka...@gmail.com>wrote:
>
>> Sorry for a late reply. It was duh moment for me.
>>
>> Just made the column type as varchar and it worked. It was char earlier.
>>
>> Thanks for your time.
>>
>> KM
>>
>>
>> On Tue, Jul 17, 2012 at 12:41 AM, Andrus Adamchik <andrus@objectstyle.org
>> > wrote:
>>
>>> Hi,
>>>
>>> so how is this entity mapped?
>>>
>>> Andrus
>>>
>>> On Jul 5, 2012, at 3:46 PM, Kanwar Manish wrote:
>>>
>>> > Hi Guys
>>> >
>>> > The statement inside the try block is causing the issue. At the end -
>>> code
>>> > from the object UserMaster is also copied.
>>> >
>>> > if ((username!=null) && (!loggedIn))
>>> > {
>>> > DataContext dc = blgetcontext.getDatacontext();
>>> >
>>> > logger.info(loginquery.toString());
>>> > List ls = dc.performQuery(loginquery);
>>> >
>>> > if ((ls == null) || ls.isEmpty() || ls.size()<1)
>>> > result = true;
>>> > else
>>> > {
>>> > result = false;
>>> > this.currentuser = ((UserMaster)ls.get(0));
>>> > try
>>> > {
>>> > this.userid = this.currentuser.getUserMasterId();
>>> > }
>>> > catch(Exception ex)
>>> > {
>>> > String s = ex.getMessage();
>>> > }
>>> >
>>> > }
>>> > }
>>> >
>>> >
>>> > Code for the UserMaster Object.....
>>> >
>>> > public UUID getUserMasterId() {
>>> > return (UUID)readProperty("userMasterId");
>>> > }
>>> >
>>> > Thanks for all the help.
>>> > Cheers
>>> > KM
>>>
>>>
>>
>
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Kanwar Manish <ka...@gmail.com>.
Sorry guys. Exception wasn't being rethrown - so I thought it worked.
Column is of type varchar(36) in PostgreSQL and it is mapped as UUID in the
cayenne mapping. In the constructor of the db class I am initiating the id.
Values are being saved perfectly fine.
"
public class UserMaster extends _UserMaster {
public UserMaster() {
this.setUserMasterId(UUID.randomUUID());
}
.........}
"
Any idea Andrus?
Thanks
KM
On Thu, Jul 19, 2012 at 4:52 PM, Kanwar Manish <ka...@gmail.com>wrote:
> Sorry for a late reply. It was duh moment for me.
>
> Just made the column type as varchar and it worked. It was char earlier.
>
> Thanks for your time.
>
> KM
>
>
> On Tue, Jul 17, 2012 at 12:41 AM, Andrus Adamchik <an...@objectstyle.org>wrote:
>
>> Hi,
>>
>> so how is this entity mapped?
>>
>> Andrus
>>
>> On Jul 5, 2012, at 3:46 PM, Kanwar Manish wrote:
>>
>> > Hi Guys
>> >
>> > The statement inside the try block is causing the issue. At the end -
>> code
>> > from the object UserMaster is also copied.
>> >
>> > if ((username!=null) && (!loggedIn))
>> > {
>> > DataContext dc = blgetcontext.getDatacontext();
>> >
>> > logger.info(loginquery.toString());
>> > List ls = dc.performQuery(loginquery);
>> >
>> > if ((ls == null) || ls.isEmpty() || ls.size()<1)
>> > result = true;
>> > else
>> > {
>> > result = false;
>> > this.currentuser = ((UserMaster)ls.get(0));
>> > try
>> > {
>> > this.userid = this.currentuser.getUserMasterId();
>> > }
>> > catch(Exception ex)
>> > {
>> > String s = ex.getMessage();
>> > }
>> >
>> > }
>> > }
>> >
>> >
>> > Code for the UserMaster Object.....
>> >
>> > public UUID getUserMasterId() {
>> > return (UUID)readProperty("userMasterId");
>> > }
>> >
>> > Thanks for all the help.
>> > Cheers
>> > KM
>>
>>
>
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Kanwar Manish <ka...@gmail.com>.
Sorry for a late reply. It was duh moment for me.
Just made the column type as varchar and it worked. It was char earlier.
Thanks for your time.
KM
On Tue, Jul 17, 2012 at 12:41 AM, Andrus Adamchik <an...@objectstyle.org>wrote:
> Hi,
>
> so how is this entity mapped?
>
> Andrus
>
> On Jul 5, 2012, at 3:46 PM, Kanwar Manish wrote:
>
> > Hi Guys
> >
> > The statement inside the try block is causing the issue. At the end -
> code
> > from the object UserMaster is also copied.
> >
> > if ((username!=null) && (!loggedIn))
> > {
> > DataContext dc = blgetcontext.getDatacontext();
> >
> > logger.info(loginquery.toString());
> > List ls = dc.performQuery(loginquery);
> >
> > if ((ls == null) || ls.isEmpty() || ls.size()<1)
> > result = true;
> > else
> > {
> > result = false;
> > this.currentuser = ((UserMaster)ls.get(0));
> > try
> > {
> > this.userid = this.currentuser.getUserMasterId();
> > }
> > catch(Exception ex)
> > {
> > String s = ex.getMessage();
> > }
> >
> > }
> > }
> >
> >
> > Code for the UserMaster Object.....
> >
> > public UUID getUserMasterId() {
> > return (UUID)readProperty("userMasterId");
> > }
> >
> > Thanks for all the help.
> > Cheers
> > KM
>
>
Re: Stumps me.....Error "java.lang.String cannot be cast to java.util.UUID"
Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,
so how is this entity mapped?
Andrus
On Jul 5, 2012, at 3:46 PM, Kanwar Manish wrote:
> Hi Guys
>
> The statement inside the try block is causing the issue. At the end - code
> from the object UserMaster is also copied.
>
> if ((username!=null) && (!loggedIn))
> {
> DataContext dc = blgetcontext.getDatacontext();
>
> logger.info(loginquery.toString());
> List ls = dc.performQuery(loginquery);
>
> if ((ls == null) || ls.isEmpty() || ls.size()<1)
> result = true;
> else
> {
> result = false;
> this.currentuser = ((UserMaster)ls.get(0));
> try
> {
> this.userid = this.currentuser.getUserMasterId();
> }
> catch(Exception ex)
> {
> String s = ex.getMessage();
> }
>
> }
> }
>
>
> Code for the UserMaster Object.....
>
> public UUID getUserMasterId() {
> return (UUID)readProperty("userMasterId");
> }
>
> Thanks for all the help.
> Cheers
> KM