I want to create the tables of a Microsoft SQL DB from objects, in Spring Boot. Is there a way to do that? If it is, can someone tell me at least the steps on how i should do that?
Asked
Active
Viewed 115 times
1 Answers
0
Yes, you can.
First, you need to create a class from your object and pass it the @Entity
annotation like so:
@Entity
public class DemoEntity {
@Id
private Long id;
private String demoStringProperty;
private Double demoDoubleProperty;
}
Then let hibernate know that it should create the entity from the class by adding this to the application.properties
file:
... database url, username, pass ...
spring.jpa.hibernate.ddl-auto=update
create-drop
insead of update
would accomplish the same thing in your case but there is a difference which you can read more in the community documentation.

S. Kostadinov
- 147
- 3
- 10
-
Yup, i tried this already, but i have the following problem. I have my class created. And in application.properties i have those lines: spring.datasource.url=jdbc:sqlserver://localhost:1433;database:BikeShopDB;integratedSecurity=true; spring.jpa.hibernate.ddl-auto=update. The problem is that i get an error saying that entityManagerFactory can t be created. – manta Jan 05 '22 at 18:52
-
-
-
I've added those in in the `application.properties`: `spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver spring.jpa.show-sql=true spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2016Dialect spring.jpa.hibernate.ddl-auto = create-drop` and now i got this `Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set` – manta Jan 05 '22 at 19:06
-
Check if [this question's answers](https://stackoverflow.com/questions/26548505/org-hibernate-hibernateexception-access-to-dialectresolutioninfo-cannot-be-null) can help you. The following error can occur when the database server is down, you use the wrong credentials, you connect to the wrong database server, etc.. – S. Kostadinov Jan 05 '22 at 19:11
-
I checked the server port to be on :1433, and its hosted by me, so it must be on localhost. it does not have credentials as i use the `integratedSecurity:true` option. – manta Jan 05 '22 at 19:13