Spring with Database (Sqlserver) already created

Asked

Viewed 51 times

0

I’m developing an application Rest API using Spring Boot.

Doubt: If I already have a Database in production with populated tables it is necessary to create the Entity class with the annotation anyway @Entity.

If yes, you need to include all fields in this table in this class ?

  • Yes Juliano, the @Entity is for the model class to work with javax.persistence.Entity, without this it will not understand that that class is part of something, is to persist, has nothing to do with generating the database (of course you can set hbm2ddl.auto like "create" in Latin, but that’s another story)

1 answer

0

Yes Juliano, you must map the class with @Entity to define the persistent objects in your database, you can map the table names and respective fields, for the fields you do not want to reflect in the database you can use the @Transient annotation.

In the persistence configuration file (xml / properties of Spring Boot) you must use the UPDATE strategy in values Hibernate.hbm2ddl.auto.

Hibernate.hbm2ddl.auto=UPDATE

<property name="hibernate.hbm2ddl.auto" value="UPDATE"/>

This algaworks article gives some good tips on JPA: https://blog.algaworks.com/tutorial-jpa/

  • I made these settings but keeps appearing an error in creating the entity class:

  • Error Creating bean with name 'ifuncionario' defined in com.portalDigital7.repository.Ifuncionario defined in @Enablejparepositories declared on Jparepositoriesregistrar.Enablejparepositoriesconfiguration: Cannot resolve Reference to bean 'jpaMappingContext' while Setting bean Property 'mappingContext'; nested Exception is org.springframework.Beans.factory.Beancreationexception: Error Creating bean with name 'jpaMappingContext': Invocation of init method failed; nested Exception is org.hibernate.service.spi.Serviceexception: Unable to create [org.hibernate.engine.jdbc.env.spi.Jdbcenvironment]

  • Can Share the Source?

  • Hi Paul posted a new question. and I put the sources. https://answall.com/questions/479948/cannot-resolve-reference-to-bean-jpamappingcontext-while-setting-bean-property

Browser other questions tagged

You are not signed in. Login or sign up in order to post.