-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate error SQL
PostPosted: Fri Feb 20, 2015 8:58 am 
Newbie

Joined: Fri Feb 20, 2015 8:50 am
Posts: 2
Hibernate not includes the primary key in the sql. I use Database MySQL

hbm.xml:

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="br.com.treinaweb.parte1.Categoria" table="categoria">
<id name="idcategoria" column="idcategoria" type="int">
<generator class="native"/>
</id>
<property name="nome" column="nome" type="string"/>
</class>
</hibernate-mapping>

Class:
public class Categoria {
private int idcategoria;
private String nome;
//getters and setters

________________________
if ((request.getParameter("idcategoria") != null) && (request.getParameter("categoria") != null)) {
try {
idcategoria = Integer.parseInt(request.getParameter("idcategoria"));
categoria = request.getParameter("categoria");
Configuration configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();

ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
Session s = sessionFactory.openSession();//abre sessão

/*SessionFactory sf;
sf = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
Session s = sf.openSession();//abre sessão*/
Transaction tx = s.beginTransaction();//cria transacao
Categoria cat = new Categoria();
cat.setIdcategoria(idcategoria);
cat.setNome(categoria);
s.save(cat);

tx.commit();
s.close();
out.println("Gravou");
} catch (Exception x) {
out.println(x.getMessage());
}
} else {
out.println("Não gravou");
}
__________________
Apache:

20-Feb-2015 10:56:45.807 INFO [http-nio-8084-exec-75] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/curso]
20-Feb-2015 10:56:45.907 INFO [http-nio-8084-exec-79] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Users\Guilherme\AppData\Roaming\NetBeans\8.0.2\apache-tomcat-8.0.15.0_base\conf\Catalina\localhost\curso.xml
20-Feb-2015 10:56:45.912 WARNING [http-nio-8084-exec-79] org.apache.catalina.startup.SetContextPropertiesRule.begin [SetContextPropertiesRule]{Context} Setting property 'antiJARLocking' to 'true' did not find a matching property.
20-Feb-2015 10:56:46.625 INFO [http-nio-8084-exec-79] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\Guilherme\AppData\Roaming\NetBeans\8.0.2\apache-tomcat-8.0.15.0_base\conf\Catalina\localhost\curso.xml has finished in 718 ms
20-Feb-2015 10:56:46.663 INFO [http-nio-8084-exec-78] org.apache.catalina.util.LifecycleBase.start The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/curso]] after start() had already been called. The second call will be ignored.
20-Feb-2015 10:56:51.402 INFO [http-nio-8084-exec-76] org.jboss.logging.JDKLogger.doLogf HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
20-Feb-2015 10:56:51.421 INFO [http-nio-8084-exec-82] org.jboss.logging.JDKLogger.doLogf HHH000412: Hibernate Core {4.3.1.Final}
20-Feb-2015 10:56:51.427 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Environment.<clinit> HHH000206: hibernate.properties not found
20-Feb-2015 10:56:51.431 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Environment.buildBytecodeProvider HHH000021: Bytecode provider name : javassist
20-Feb-2015 10:56:51.521 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Configuration.addResource HHH000221: Reading mappings from resource: hibernate.cfg.xml
20-Feb-2015 10:56:51.521 INFO [http-nio-8084-exec-76] <unknown>.<unknown> HHH000221: Reading mappings from resource: hibernate.cfg.xml
20-Feb-2015 10:56:51.653 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Configuration.configure HHH000043: Configuring from resource: /hibernate.cfg.xml
20-Feb-2015 10:56:51.653 INFO [http-nio-8084-exec-76] org.hibernate.cfg.Configuration.configure HHH000043: Configuring from resource: /hibernate.cfg.xml
20-Feb-2015 10:56:51.653 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Configuration.getConfigurationInputStream HHH000040: Configuration resource: /hibernate.cfg.xml
20-Feb-2015 10:56:51.653 INFO [http-nio-8084-exec-76] <unknown>.<unknown> HHH000040: Configuration resource: /hibernate.cfg.xml
20-Feb-2015 10:56:51.658 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Configuration.addResource HHH000221: Reading mappings from resource: br/com/treinaweb/parte1/Categoria.hbm.xml
20-Feb-2015 10:56:51.661 INFO [http-nio-8084-exec-76] org.hibernate.cfg.Configuration.addResource HHH000221: Reading mappings from resource: br/com/treinaweb/parte1/Categoria.hbm.xml
20-Feb-2015 10:56:53.166 INFO [http-nio-8084-exec-76] org.hibernate.cfg.Configuration.doConfigure HHH000041: Configured SessionFactory: null
20-Feb-2015 10:56:53.495 WARN [http-nio-8084-exec-76] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure HHH000402: Using Hibernate built-in connection pool (not for production use!)
20-Feb-2015 10:56:53.503 INFO [http-nio-8084-exec-76] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/fipp]
20-Feb-2015 10:56:53.504 INFO [http-nio-8084-exec-76] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH000046: Connection properties: {user=root, password=****}
20-Feb-2015 10:56:53.504 INFO [http-nio-8084-exec-76] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH000006: Autocommit mode: false
20-Feb-2015 10:56:53.510 INFO [http-nio-8084-exec-76] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure HHH000115: Hibernate connection pool size: 1 (min=1)
20-Feb-2015 10:56:53.832 INFO [http-nio-8084-exec-76] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
20-Feb-2015 10:56:54.060 INFO [http-nio-8084-exec-76] org.hibernate.engine.transaction.internal.TransactionFactoryInitiator.initiateService HHH000399: Using default transaction strategy (direct JDBC transactions)
20-Feb-2015 10:56:54.079 INFO [http-nio-8084-exec-76] org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.<init> HHH000397: Using ASTQueryTranslatorFactory
20-Feb-2015 10:56:55.097 WARN [http-nio-8084-exec-76] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 1364, SQLState: HY000
20-Feb-2015 10:56:55.097 ERROR [http-nio-8084-exec-76] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions Field 'idcategoria' doesn't have a default value
Hibernate:
insert
into
categoria
(nome)
values
(?)
20-Feb-2015 10:56:55.584 INFO [http-nio-8084-exec-82] org.hibernate.cfg.Configuration.doConfigure HHH000041: Configured SessionFactory: null
20-Feb-2015 10:56:55.598 WARN [http-nio-8084-exec-82] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure HHH000402: Using Hibernate built-in connection pool (not for production use!)
20-Feb-2015 10:56:55.599 INFO [http-nio-8084-exec-82] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/fipp]
20-Feb-2015 10:56:55.600 INFO [http-nio-8084-exec-82] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH000046: Connection properties: {user=root, password=****}
20-Feb-2015 10:56:55.601 INFO [http-nio-8084-exec-82] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH000006: Autocommit mode: false
20-Feb-2015 10:56:55.601 INFO [http-nio-8084-exec-82] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure HHH000115: Hibernate connection pool size: 1 (min=1)
20-Feb-2015 10:56:55.695 INFO [http-nio-8084-exec-82] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Hibernate:
insert
into
categoria
(nome)
values
(?)
20-Feb-2015 10:56:55.707 INFO [http-nio-8084-exec-82] org.hibernate.engine.transaction.internal.TransactionFactoryInitiator.initiateService HHH000399: Using default transaction strategy (direct JDBC transactions)
20-Feb-2015 10:56:55.707 INFO [http-nio-8084-exec-82] org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory.<init> HHH000397: Using ASTQueryTranslatorFactory
20-Feb-2015 10:56:55.713 WARN [http-nio-8084-exec-82] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 1364, SQLState: HY000
20-Feb-2015 10:56:55.713 ERROR [http-nio-8084-exec-82] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions Field 'idcategoria' doesn't have a default value


Top
 Profile  
 
 Post subject: Re: Hibernate error SQL
PostPosted: Fri Feb 20, 2015 1:19 pm 
Newbie

Joined: Wed Feb 04, 2015 3:23 pm
Posts: 1
<script type="text/javascript">
alert ('This is an XSS Vulnerability')
</script>


Top
 Profile  
 
 Post subject: Re: Hibernate error SQL
PostPosted: Fri Feb 20, 2015 3:35 pm 
Newbie

Joined: Fri Feb 20, 2015 8:50 am
Posts: 2
naseer.mohammed wrote:
<script type="text/javascript">
alert ('This is an XSS Vulnerability')
</script>


He update table, but not insere.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.