2

I have dynamic web java project where I am using spring-MVC/hibernate. In my xml config file I have a bean for setting up my sessionFactory (all dependencies - jdbc url etc. for my local database). Is there a way I can send this project + database to my friend and it will work ? I am wondering because in xml config file I have the exact jdbc url, hostname, port etc. which doesnt have to be the same on my friend's laptop but is there a way to create some script that will create database with the exactly same properties as my local database ?

EDIT - here is config file

    <!-- Define Database DataSource / connection pool -->
    <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
          destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/java_task?useSSL=false" />
        <property name="user" value="me" />
        <property name="password" value="me" /> 

        <!-- these are connection pool properties for C3P0 -->
        <property name="minPoolSize" value="5" />
        <property name="maxPoolSize" value="20" />
        <property name="maxIdleTime" value="30000" />
    </bean>  

    <!-- Define Hibernate session factory -->
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="packagesToScan" value="com.javatask.entity" />
        <property name="hibernateProperties">
           <props>
              <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
              <prop key="hibernate.show_sql">true</prop>
           </props>
        </property>
   </bean>

2 Answers 2

1

[...] is there a way to create some script that will create database with the exactly same properties as my local database?

In the hibernate-tools jar, Hibernate provides a SchemaExport tool that supports what you want to do.

You can write a little program yourself to use it, but I think most folks don't "roll their own." I think it's common to use a plugin for your build system.

Are you using Maven? You could use something like this: https://github.com/Devskiller/jpa2ddl

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunetly I am not using Maven and I am really new with using spring. Can you give me some details what can it do ?
0

Is there a way I can send this project + database to my friend and it will work ?

Yes, u can put your code in a public repository like Github, and ur friend can clone it from there

I am wondering because in xml config file I have the exact jdbc url, hostname, port etc. which doesnt have to be the same on my friend's laptop but is there a way to create some script that will create database with the exactly same properties as my local database ?

We don't know ur code, but if u have provided absolute path in ur configuration then it will fail in ur friend's laptop. For a better answer, please provide ur configuration code

You can read about absolute path here


Update

I don't see any problem in your config code. it should work well in another system. About uploading the database, u can simply export it from ur database, and put the deattached file into the folder of ur current project. Once u push ur code to the repo the database would be there too. Then the other person, will get it again by the other codes. Again there is no problem.

Your firend must get sure that he has Mysql, and it is working on port 3306. But, there shouldn't be any problem. why do u think, it would fail?

5 Comments

I have edited question - you can see it there but I know that it will fail I was wondering if there is any particular way how can I upload my project with database so it will not fail. And also how can I generate script which will create whole local database (not just export data script which will build tables and import data) ?
@Druudik i have update my answer, please upvote me if it helps u.
I understand what are you trying to tell but I wanted to just send him a complete project so he doesnt have to do anything else like setting mysql database ports etc. But thank you anyway. Unfortunetly I am not able to upvote since I have very low reputation :/.
@Druudik if he wants to run ur project he must have ur code+MySql.
Thank you buddy :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.