db-jdo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Bouschen <michael.bousc...@akquinet.de>
Subject Re: How to annotate a column to represent "int unsigned" datatype ?
Date Sun, 01 Jul 2012 21:22:16 GMT
Hi,

I'm wondering why the error message says "the SQL type INT(11) UNSIGNED 
declared for field of java type java.lang.Integer". So maybe the error 
is not on the annotations for class Test, but for the referred class 
Member. What is the primary key for class member? You cannot use an 
Integer or int, because INT(11) may hold values that cause an overflow. 
So the primary key field in Member should be a long field.

Regards Michael

> First of all, thank you both for your time :)
>
> Michael, I'm very sorry it didn't work. I can't figure out the difference
> between sqlType and jdbcType !
>
> I tried your suggestions with different flavors such as (INTEGER(11)
> UNSIGNED and switched cases) but none worked.
>
> @Column(sqlType = "INT(11) UNSIGNED", defaultValue = "1")
> private Member member;
>
>
> But all attempts brought up that exception (Or what reflects the sqlType
> value), I alos tried these combinations with jdbcType but didn't too:
> *(TclRequest2 is the class with the mapping I'm trying to test and the main
> method initializing the test)*
>
> javax.jdo.JDOFatalInternalException: SQL type INT(11) UNSIGNED declared for
> field of java type java.lang.Integer cant be mapped for this datastore.
> at
> org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:562)
> at
> org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:745)
> at
> org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:765)
> at
> com.skycomm.services.dao.impl.GenericDAOImpl.saveAndDetach(GenericDAOImpl.java:267)
> at com.skycomm.ixload.TclRequest2.main(TclRequest2.java:58)
> NestedThrowablesStackTrace:
> SQL type INT(11) UNSIGNED declared for field of java type java.lang.Integer
> cant be mapped for this datastore.
> org.datanucleus.exceptions.NucleusException: SQL type INT(11) UNSIGNED
> declared for field of java type java.lang.Integer cant be mapped for this
> datastore.
> at
> org.datanucleus.store.rdbms.mapping.RDBMSMappingManager.getDatastoreMappingClass(RDBMSMappingManager.java:305)
> at
> org.datanucleus.store.rdbms.mapping.RDBMSMappingManager.createDatastoreMapping(RDBMSMappingManager.java:564)
> at
> org.datanucleus.store.mapped.mapping.PersistableMapping.prepareDatastoreMapping(PersistableMapping.java:246)
> at
> org.datanucleus.store.mapped.mapping.PersistableMapping.initialize(PersistableMapping.java:113)
> at
> org.datanucleus.store.mapped.mapping.MappingFactory.createMapping(MappingFactory.java:97)
> at
> org.datanucleus.store.mapped.mapping.AbstractMappingManager.getMapping(AbstractMappingManager.java:255)
> at
> org.datanucleus.store.rdbms.table.ClassTable.manageMembers(ClassTable.java:540)
> at
> org.datanucleus.store.rdbms.table.ClassTable.manageClass(ClassTable.java:420)
> at
> org.datanucleus.store.rdbms.table.ClassTable.initializeForClass(ClassTable.java:1080)
> at
> org.datanucleus.store.rdbms.table.ClassTable.initialize(ClassTable.java:267)
> at
> org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.initializeClassTables(RDBMSStoreManager.java:2452)
> at
> org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.addClassTablesAndValidate(RDBMSStoreManager.java:2359)
> at
> org.datanucleus.store.rdbms.RDBMSStoreManager$ClassAdder.run(RDBMSStoreManager.java:2009)
> at
> org.datanucleus.store.rdbms.AbstractSchemaTransaction.execute(AbstractSchemaTransaction.java:113)
> at
> org.datanucleus.store.rdbms.RDBMSStoreManager.addClasses(RDBMSStoreManager.java:820)
> at
> org.datanucleus.store.AbstractStoreManager.addClass(AbstractStoreManager.java:1163)
> at
> org.datanucleus.store.mapped.MappedStoreManager.getDatastoreClass(MappedStoreManager.java:383)
> at
> org.datanucleus.store.rdbms.fieldmanager.DynamicSchemaFieldManager.storeObjectField(DynamicSchemaFieldManager.java:98)
> at
> org.datanucleus.state.AbstractStateManager.providedObjectField(AbstractStateManager.java:1452)
> at com.skycomm.ixload.TclRequest2.jdoProvideField(TclRequest2.java)
> at com.skycomm.ixload.TclRequest2.jdoProvideFields(TclRequest2.java)
> at
> org.datanucleus.state.AbstractStateManager.provideFields(AbstractStateManager.java:1520)
> at
> org.datanucleus.store.rdbms.RDBMSPersistenceHandler.checkForSchemaUpdatesForFieldsOfObject(RDBMSPersistenceHandler.java:634)
> at
> org.datanucleus.store.rdbms.RDBMSPersistenceHandler.insertObject(RDBMSPersistenceHandler.java:119)
> at
> org.datanucleus.state.JDOStateManager.internalMakePersistent(JDOStateManager.java:2371)
> at
> org.datanucleus.state.JDOStateManager.makePersistent(JDOStateManager.java:2347)
> at
> org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.java:1798)
> at
> org.datanucleus.ObjectManagerImpl.persistObjectWork(ObjectManagerImpl.java:1647)
> at
> org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java:1504)
> at
> org.datanucleus.api.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceManager.java:740)
> at
> org.datanucleus.api.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceManager.java:765)
> at
> com.skycomm.services.dao.impl.GenericDAOImpl.saveAndDetach(GenericDAOImpl.java:267)
> at com.skycomm.ixload.TclRequest2.main(TclRequest2.java:58)
> Exception in thread "main" java.lang.NullPointerException
> at com.skycomm.ixload.TclRequest2.main(TclRequest2.java:58)
>
>
> Thanks a lot :)
>
> On Sun, Jul 1, 2012 at 2:04 PM, Michael Bouschen <
> michael.bouschen@akquinet.de> wrote:
>
>> Hi,
>>
>> I'm not sure whether I understand he issue correctly. What I understood is
>> that you want Datanucleus to create the table for your class Test. But the
>> generated table does not have the correct column type for the foreign key,
>> since it is not unsigned.
>>
>> The @Column annotation has an attribute called sqlType that allows you to
>> declare the type of the column in the database (in your case "INT(11)
>> UNSIGNED"). I'm note sure whether you can have both jdbcType and sqlType. I
>> would skip the jdbcType and length when specifying sqlType.
>>
>> Hope this helps.
>>
>> Regards Michael
>>
>>
>>   Hi everyone,
>>> Here is a sample of my mapping:[code]@**PersistenceCapable(**identityType
>>> =
>>> IdentityType.APPLICATION, detachable = "true")
>>> public class Test {
>>>       @PrimaryKey
>>>       @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>>>       private long id;
>>>       @Persistent(column = "user")
>>>       @Column(defaultValue = "1", jdbcType = "INTEGER", length =
>>> 11,allowsNull = "false")
>>>       private Member member;
>>>
>>>       //Getters and setters
>>> }[/code]I'm using MySQL.
>>> I have my object (Test) with a field that maps another object (Member)
>>> that
>>> I'm not allowed to alter it's table. Member's id column type "INT(11)
>>> UNSIGNED"
>>>
>>> Datanucleus (A JDO implementation) is unable to create the "Test" table
>>> because it's "user" column will have to have a foreign-key constraint to
>>> point at "Member"'s PK column which is "INT(11)  UNSIGNED". I managed to
>>> specify it's type and length but I can't specify that it's
>>> [b]UNSIGNED[/b] !
>>>
>>> I suppose this can be done using extensions but I can't find a clear and
>>> detailed specification for the available extensions.
>>>
>>> I reached that page, looked through some of the api docs but found
>>> nothing.
>>>
>>> I generally find the extensions annotation very critical sometimes but I
>>> can't find where is it's specification ?!
>>>
>>> I feel terribly lost right now !
>>>
>>>
>> --
>> *Michael Bouschen*
>> *Prokurist*
>>
>> akquinet tech@spree GmbH
>> Bülowstr. 66, D-10783 Berlin
>>
>> Fon:   +49 30 235 520-33
>> Fax:   +49 30 217 520-12
>> Email: michael.bouschen@akquinet.de
>> Web: www.akquinet.de <http://www.akquinet.de>
>>
>> akquinet tech@spree GmbH, Berlin
>> Geschäftsführung: Martin Weber, Dr. Torsten Fink
>> Amtsgericht Berlin-Charlottenburg HRB 86780 B
>> USt.-Id. Nr.: DE 225 964 680
>>
>
>


-- 
*Michael Bouschen*
*Prokurist*

akquinet tech@spree GmbH
Bülowstr. 66, D-10783 Berlin

Fon:   +49 30 235 520-33
Fax:   +49 30 217 520-12
Email: michael.bouschen@akquinet.de
Web: www.akquinet.de <http://www.akquinet.de>

akquinet tech@spree GmbH, Berlin
Geschäftsführung: Martin Weber, Dr. Torsten Fink
Amtsgericht Berlin-Charlottenburg HRB 86780 B
USt.-Id. Nr.: DE 225 964 680

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message