You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Peter Tan <pe...@hotmail.com> on 2008/12/15 10:24:13 UTC

Convert boolean to String type using ExternalValues

Hi,

I have a boolean field that I'd like to map to a string column in DB, so I wrote the following annotation:

    @ExternalValues({"true=TRUE", "false=FALSE"})
    @Type(String.class)
    @Column(name="is_verified")
    private boolean isVerified;

And I got ClassCastException:

Caused by: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    at org.apache.openjpa.enhance.ReflectingPersistenceCapable.pcProvideField(ReflectingPersistenceCapable.java:126)
    at org.apache.openjpa.kernel.StateManagerImpl.provideField(StateManagerImpl.java:3012)
    at org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2827)
    at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:39)
    ... 29 more

Somehow the external value transfer didn't happen and the type cast failed. Any idea?

thank you
-Peter
 

_________________________________________________________________
Send e-mail faster without improving your typing skills.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_speed_122008

Re: Convert boolean to String type using ExternalValues

Posted by Cosmin <co...@intrasoft-intl.com>.
Hi,

I have a situation where I need to map a Boolean with ExternalValues. The problem is that the fiels has to be nullable and when it is null the mapping fails. An OpenJPA error is thrown saying that the null value is unknown.

I tried mapping null=null. Not working. I need the mapping only for true and false. When the object is null I need to update the db with null.

Anybody... any ideas?

Thanks!
-- 
View this message in context: http://n2.nabble.com/Convert-boolean-to-String-type-using-ExternalValues-tp1659239p2592990.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Convert boolean to String type using ExternalValues

Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
 Revision 726927 [1]  addresses the issue of Externalizer with runtime
enhancement.
If possible, please run your test application with runtime enhancement
against the nightly build that includes this commit, and let us know.

[1]
http://n2.nabble.com/svn-commit%3A-r726927----openjpa-trunk-openjpa-kernel-src-main-java-org-apache-openjpa-enhance-ReflectingPersistenceCapable.java-tt1660997.html

-- 
View this message in context: http://n2.nabble.com/Convert-boolean-to-String-type-using-ExternalValues-tp1659239p1661071.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Convert boolean to String type using ExternalValues

Posted by ptan <pe...@hotmail.com>.
Ah yeah...  I was using runtime enhancement. Switching to the build-time
enhancement solved this issue. tyvm!


Pinaki Poddar wrote:
> 
> Hi, 
>   Have you enhanced your persistent entities?
>   Externalization has some issues with runtime enhancement -- AFAIR -- but
> someone more familiar with runtime enhancement may be able to elaborate
> further.
> 
>   In any case, if the persistent entities have not been enhanced at
> build-time, please do so and verify if externalization works with enhanced
> classes.
> 

-- 
View this message in context: http://n2.nabble.com/Convert-boolean-to-String-type-using-ExternalValues-tp1659239p1660663.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Convert boolean to String type using ExternalValues

Posted by Pinaki Poddar <pp...@apache.org>.
Hi, 
  Have you enhanced your persistent entities?
  Externalization has some issues with runtime enhancement -- AFAIR -- but
someone more familiar with runtime enhancement may be able to elaborate
further.

  In any case, if the persistent entities have not been enhanced at
build-time, please do so and verify if externalization works with enhanced
classes.


-- 
View this message in context: http://n2.nabble.com/Convert-boolean-to-String-type-using-ExternalValues-tp1659239p1660381.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Re: Convert boolean to String type using ExternalValues

Posted by ptan <pe...@hotmail.com>.
Thanks for looking into this. I'm using version 1.2.0.

Here is the schema:
CREATE TABLE testtable (
	id BIGINT NOT NULL AUTO_INCREMENT,
	verified CHAR(10) NOT NULL DEFAULT 'False',
	KEY (id)
)

Entity:

@Entity
@Table(name="testtable")
public class TestTable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private long id;

    @ExternalValues({"true=TRUE", "false=FALSE"})
    @Type(String.class)
    private boolean verified;
}

Test:

    @Test
    public void testcase() {
        em.getTransaction().begin();
        em.persist(new TestTable());
        em.getTransaction().commit();        
    }



Sandhya Kishore wrote:
> 
> Hi Peter,
> 
>     I tested the scenario that you mentioned but it worked fine. Could you
> give me your testcase to reproduce the problem? Pls have a look at my
> simple testcase that I wrote to reproduce the problem. Which version of
> openjpa are you using?
> 
> 
> Thanks
> Sandhya
> 

-- 
View this message in context: http://n2.nabble.com/Convert-boolean-to-String-type-using-ExternalValues-tp1659239p1660187.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.