Commit 1260edcf authored by cherrylzhao's avatar cherrylzhao
Browse files

remove id column for country table.

parent 0b654e10
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -23,22 +23,12 @@ public class Country implements Serializable {

    private static final long serialVersionUID = 4522167390518926493L;

    private long id;
    
    private String code;

    private String name;

    private String language;

    public long getId() {
        return id;
    }

    public void setId(final long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }
@@ -65,6 +55,6 @@ public class Country implements Serializable {

    @Override
    public String toString() {
        return String.format("id: %s, code: %s, name: %s, language: %s", id, code, name, language);
        return String.format("code: %s, name: %s, language: %s", code, name, language);
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ public final class CountryRepositoryImpl implements CountryRepository {

    @Override
    public void createTableIfNotExists() {
        String sql = "CREATE TABLE IF NOT EXISTS t_country (id BIGINT NOT NULL AUTO_INCREMENT, code VARCHAR(50), name VARCHAR(50), language VARCHAR(50), PRIMARY KEY (id))";
        String sql = "CREATE TABLE IF NOT EXISTS t_country (code VARCHAR(50), name VARCHAR(50), language VARCHAR(50), PRIMARY KEY (code))";
        try (Connection connection = dataSource.getConnection();
             Statement statement = connection.createStatement()) {
            statement.executeUpdate(sql);
@@ -106,10 +106,9 @@ public final class CountryRepositoryImpl implements CountryRepository {
             ResultSet resultSet = preparedStatement.executeQuery()) {
            while (resultSet.next()) {
                Country country = new Country();
                country.setId(resultSet.getLong(1));
                country.setCode(resultSet.getString(2));
                country.setName(resultSet.getString(3));
                country.setLanguage(resultSet.getString(4));
                country.setCode(resultSet.getString(1));
                country.setName(resultSet.getString(2));
                country.setLanguage(resultSet.getString(3));
                result.add(country);
            }
        } catch (final SQLException ignored) {
+1 −9
Original line number Diff line number Diff line
@@ -18,11 +18,10 @@
package org.apache.shardingsphere.example.common.jpa.entity;

import org.apache.shardingsphere.example.common.entity.Country;
import org.springframework.context.annotation.Primary;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@@ -31,13 +30,6 @@ import javax.persistence.Table;
public class CountryEntity extends Country {

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Override
    public long getId() {
        return super.getId();
    }
    
    @Column(name = "code")
    @Override
    public String getCode() {
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
    </resultMap>

    <update id="createTableIfNotExists">
        CREATE TABLE IF NOT EXISTS t_country (id BIGINT NOT NULL AUTO_INCREMENT, code VARCHAR(50), name VARCHAR(50), language VARCHAR(50), PRIMARY KEY (id));
        CREATE TABLE IF NOT EXISTS t_country (code VARCHAR(50), name VARCHAR(50), language VARCHAR(50), PRIMARY KEY (code));
    </update>

    <update id="truncateTable">
@@ -20,7 +20,7 @@
        DROP TABLE IF EXISTS t_country;
    </update>

    <insert id="insert" useGeneratedKeys="true" keyProperty="id">
    <insert id="insert">
        INSERT INTO t_country (code, name, language) VALUES (#{code,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR})
    </insert>

+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@
                <sharding:broadcast-table-rule table="t_country" />
            </sharding:broadcast-table-rules>
        </sharding:sharding-rule>
        <sharding:props>
            <prop key="sql.show">true</prop>
        </sharding:props>
    </sharding:data-source>
    
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">