Page 1 of 1

Doubts about a product attribute

Posted: Thu May 05, 2011 11:16 pm
by Serena
Hello,

I'm really new to Spring (actually, to all the tecnologies involved in the project) and I have many doubts about the system. I need to change the default HQSQL database to a MySQL one with my data, trying to match the data model with my data.

I haven´t done any changes on the site, so I don't expect to work itself but at least a first preview of the index.

Yesterday, when I ran the Tomcat server, I got this error:

INFO: foreign keys: []
04-may-2011 16:02:30 org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: []
04-may-2011 16:02:30 org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
[ INFO] 16:02:33 RuntimeEnvironmentPropertiesConfigurer - Loading properties file from class path resource [config/bc/production.properties]
[ INFO] 16:02:33 RuntimeEnvironmentPropertiesConfigurer - Loading properties file from class path resource [config/bc/common.properties]
[DEBUG] 16:02:43 MergeXmlWebApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@19546ee]
04-may-2011 16:02:43 org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'bl'
[ INFO] 16:02:43 SearchServiceCompassImpl - Rebuilding product index
[ERROR] 16:02:44 JobRunShell - Job DEFAULT.indexCreationJob threw an unhandled Exception:
org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'rebuildProductIndex' on target class [class $Proxy78] failed; nested exception is javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of org.broadleafcommerce.catalog.domain.ProductImpl.isMachineSortable

So I updated the database, changing all the values to TRUE in the IS_MACHINE_SORTABLE field. And it worked seamless, and I could ran the server and load the web on a browser.

So now, I have some questions: ¿What is this Product attribute for? ¿Why it doen't work, if there is a null value? There isn't a not null constraint on the HQSQL script. I'm sure I'm missing something else as I don't know neither Quartz nor Hibernate.

Thanks for all your help in advance

Re: Doubts about a product attribute

Posted: Fri May 06, 2011 5:29 am
by jefffischer
This is more of a Hibernate thing than anything else. If the field on the entity is a primitive boolean, then Hibernate expects that there has to be a value in the database, since Java itself does not allow a null value for a primitive boolean. If the field is of Boolean type instead, then it's a different story, since Boolean is a class and is not a primitive. The value for a Boolean field can be null.

As for the HSQL script not specifying a "not-null" constraint on that field, this sound like an oversight in the auto-ddl generation performed by Hibernate when it emits the ddl. As far as Hibernate is concerned, this field would always have a value if you're using the Java entities, since primitive boolean fields are assumed to have a value of false until otherwise specified. It's when the database is seeded from elsewhere that it's possible to run into problems for a field like this.

As for the field itself, this field is possibly used as part of shipping calculation. Some shipping vendors want to know as part of their shipping price calculation whether or not the parcel can be handled by a machine, or if the package is delicate and must be handled by a human.

Re: Doubts about a product attribute

Posted: Sun May 08, 2011 10:34 pm
by Serena
Hi jefffischer,

Thank you very much for your response, now everything makes sense!!

Sometimes the easiest things are harder to see...

Best wishes,

Serena

Re: Doubts about a product attribute

Posted: Tue Aug 16, 2011 3:43 pm
by Stjeffimn
hi all...

Re: Doubts about a product attribute

Posted: Sat Sep 03, 2011 2:22 pm
by rpierre33
Well, java does not really allow a primitive boolean field to be jul so this needs some sort of entry to fill it in.

I am not that familiar with how the back end hibernate works so we should just alleviate concerns for that and just take it as it is.

I know though that when performing a hibernate, java ensures that a value would be assigned to it no matter what since they are assumed to be false until otherwise specified.