Id Generator

sahili

Mitglied
Hallo zusammen!
Ich habe folgendes Problem: Id ist immer null bwz folgende Fehlermeldung:

Caused by: java.sql.SQLException: Attempt to insert null into a non-nullable column: column: ID table: USER in statement
at org.hsqldb.jdbc.Util.throwError(Unknown Source)

die Aufgabe eine Anwendung mittels Spring und Hibernate zu schreiben um daten von User und die genutzte Applikation in Hsql zu persistieren.
die User Klasse sieht folgendes Aus:
Code:
@Entity 
@Table (name="User", 
uniqueConstraints = {@UniqueConstraint(columnNames={"name", "server", "mandant"})} )
publicclass User implements Serializable {
// serial version
private staticf inallongserialVersionUID = 1667568389832048492L;
// 
public static final User NOBODY = new User (-1);
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id=1;
@Column
private String name;
@Column
private String server;
@Column
private String password;
@Column
]private String mandant;
 

public User() {
 
 
*@paramid
private User (Integer id) {
this.id = id;
this.name = "*";
this.server = "*";
this.mandant = "*";
}

/**
*
*@paramname
*@paramserver
*/
public User (String name, String server) {
super();
this.name = name;
this.server = server;
this.mandant = "*";
}
/**
*
*@paramname
*@paramserver
*@parammandant
*/
public User(String name, String server, String mandant) {
super();
this.name = name;
this.server = server;
this.mandant = mandant;
}
/**
*@returntheid
*/
 
public Integer getId() {
returnid;
 
/**
*@paramid
*theidtoset
 
publicvoid setId (Integer id) {
this.id = id;
 
*@returnthename
 
public String getName() {
returnname;
 
 
*@paramname
*thenametoset

publicvoid setName(String name) {
this.name = name;
 
 
 
*@returntheserver
public String getServer() {
returnserver
*@paramserver
 
publicvoid setServer(String server) {
this.server = server;
}
}
 
Ein Teil des Testprogramms:
 
User user1 = new User("m","n","s");
userDao.merge(user1);
userDao ist die Klasse für die Persistenzschicht.
wie kann ich bittte vorgehen.

MfG.
 
Hallo,

ich glaube es wäre gut, wenn du mal das DAO zeigst. :)
Die Mapping-XML zum User wäre auch noch nicht so schlecht.

MFG

zEriX
 
Persistence.xml:


Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="userContext"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.provider_class"
value="org.hibernate.cache.NoCacheProvider" />
<property name="hibernate.connection.driver_class"
value="org.hsqldb.jdbcDriver" />
<property name="hibernate.connection.username" value="sa" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.connection.url"
value="jdbc:hsqldb:file:c:/usercontext;runtime.gc_interval=10000;hsqldb.default_table_type=cached;" />
</properties>
</persistence-unit>
</persistence>
und ApplicationContext.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd" >



<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="userContext" />
</bean>

<bean id="userDao" class="de.seg.ea.config.server.dao.jpa.JpaUserDao">
<property name="entityManagerFactory"
ref="entityManagerFactory" />
</bean>
<tx:advice id="txAdvice"
transaction-manager="jpaTransactionManager">
<tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="daoMethods"
expression="execution(* de.seg.ea.config.server.dao.*Dao.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="daoMethods" />
</aop:config>

</beans>
 
Ah, also du arbeitest mit der JPA.

Das DAO hast du aber immer noch nicht gepostet. Den SourceCode würde ich gerne sehen. In den XML-Dateien kann ich auf den ersten Blick keine Fehler erkennen.

MFG

zEriX
 

Neue Beiträge

Zurück