Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.sql.SQLException: This function is not supported using HSQL and Spring
    primarykey
    data
    text
    <p>Can someone please tell me why am I geting java.sql.SQLException: This function is not supported using HSQL and Spring? I am trying to insert a new row into my database..</p> <p>Below is my DAO and I get the error on the mySession.save(message) line:</p> <pre><code>@Transactional @Repository public class MessageDaoImpl implements MessageDao { private Log log = null; @Autowired private SessionFactory sessionFactory; public MessageDaoImpl() { super(); log = LogFactory.getLog(MessageDaoImpl.class); } @SuppressWarnings("unchecked") @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public List&lt;Message&gt; listMessages() { try { return (List&lt;Message&gt;) sessionFactory.getCurrentSession() .createCriteria(Message.class).list(); } catch (Exception e) { log.fatal(e.getMessage()); return null; } } @SuppressWarnings("unchecked") @Transactional(readOnly = false, propagation = Propagation.REQUIRED) public void SaveOrUpdateMessage(Message message) { try { Session mySession = sessionFactory.getCurrentSession(); mySession.save(message); mySession.flush(); } catch (Exception e) { log.fatal(e.getMessage()); } } } </code></pre> <p>Here is my main class:</p> <pre><code>public static void main(String[] args) { ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfig.class); MessageService mService = context.getBean(MessageService.class); HelloWorld helloWorld = context.getBean(HelloWorld.class); /** * Date: 4/26/13 / 9:26 AM * Comments: * * I added Log4J to the example. */ LOGGER.debug("Message from HelloWorld Bean: " + helloWorld.getMessage()); Message message = new Message(); message.setMessage(helloWorld.getMessage()); // mService.SaveMessage(message); helloWorld.setMessage("I am in Staten Island, New York"); LOGGER.debug("Message from HelloWorld Bean: " + helloWorld.getMessage()); } } </code></pre> <p>Here is my DatabaseConfig:</p> <pre><code>public class DatabaseConfig { private static final Logger LOGGER = getLogger(DatabaseConfig.class); @Autowired Environment env; @Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL). addScript("schema.sql").build(); return db; } @Bean public DataSource hsqlDataSource() { BasicDataSource ds = new BasicDataSource(); try { ds.setDriverClassName("org.hsqldb.jdbcDriver"); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:hsqldb:mem:mydb"); } catch (Exception e) { LOGGER.error(e.getMessage()); } return ds; } @Bean public SessionFactory sessionFactory() { LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean(); factoryBean.setDataSource(hsqlDataSource()); factoryBean.setHibernateProperties(getHibernateProperties()); factoryBean.setPackagesToScan(new String[]{"com.xxxxx.HelloSpringJavaBasedJavaConfig.model"}); try { factoryBean.afterPropertiesSet(); } catch (IOException e) { LOGGER.error(e.getMessage()); e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return factoryBean.getObject(); } @Bean public Properties getHibernateProperties() { Properties hibernateProperties = new Properties(); hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); hibernateProperties.setProperty("hibernate.use_sql_comments", env.getProperty("hibernate.use_sql_comments")); hibernateProperties.setProperty("hibernate.format_sql", env.getProperty("hibernate.format_sql")); hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); hibernateProperties.setProperty("hibernate.generate_statistics", env.getProperty("hibernate.generate_statistics")); hibernateProperties.setProperty("javax.persistence.validation.mode", env.getProperty("javax.persistence.validation.mode")); //Audit History flags hibernateProperties.setProperty("org.hibernate.envers.store_data_at_delete", env.getProperty("org.hibernate.envers.store_data_at_delete")); hibernateProperties.setProperty("org.hibernate.envers.global_with_modified_flag", env.getProperty("org.hibernate.envers.global_with_modified_flag")); return hibernateProperties; } @Bean public HibernateTransactionManager hibernateTransactionManager() { HibernateTransactionManager htm = new HibernateTransactionManager(); htm.setSessionFactory(sessionFactory()); htm.afterPropertiesSet(); return htm; } } </code></pre> <p>and here is what I am getting to the console:</p> <pre><code>Exception in thread "main" org.hibernate.AssertionFailure: null id in com.xxx.HelloSpringJavaBasedJavaConfig.model.Message entry (don't flush the Session after an exception occurs) </code></pre> <p>Here is my message model bean:</p> <pre><code>@Entity @Table(name = "messages") public class Message { @Id @Column(name = "id") @GeneratedValue(strategy = GenerationType.AUTO) private String id; @Column(name = "message") private String message; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } @Override public String toString() { return "Message{" + "id='" + id + '\'' + ", message='" + message + '\'' + '}'; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload