#production vs development

270 messages Β· Page 1 of 1 (latest)

covert hawk
#

is it necessary to change the structure of db while in production? as i was not getting a single exception and was working fine in development but when i deployed it, Db has started giving me errors

lapis umbraBOT
#

βŒ› This post has been reserved for your question.

Hey @covert hawk! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mint night
#

normally not

#

if yu show us the what exactly you are doing as well as the errors, we might be able to help you

#

If you change the DB structure for the application in development and you deploy that to production, you do have to perform equivalent changes there ofc

covert hawk
#

should i also send the log of production server?

mint night
#

your application references a table that isn't in the DB

#

if you add an entity, you also need to add the table in the DB

#

DB migrations can be useful for that purpose

covert hawk
#

i am using hibernate and hiibernate managees my db tables

mint night
#

Do you mean you configured automatic table updating?

smoky hemlock
#
# JPA Configuration
spring.jpa.hibernate.ddl-auto=update

?

covert hawk
#

yes

mint night
#

Are you sure you don't have that overwritten anywhere?

#

But in general, doing that is probably a bad idea

covert hawk
#

then what is the preffered way?

smoky hemlock
#

Sometimes, ddl-auto=update only runs during application startup if there are changes detected in the entity mappings. If there is any issue with the entity itself (like missing annotations or improper configuration), Hibernate might not attempt to create the new table. Double-check your entity class to ensure the table and field mappings are correct.
Enable detailed logging for Hibernate to see if it is trying to update the schema and to check for any errors related to schema validation or creation.

logging.level.org.hibernate.tool.hbm2ddl=DEBUG
logging.level.org.hibernate.SQL=DEBUG

Does it create the table in development but not production?

mint night
covert hawk
smoky hemlock
#

And yes I never used flyway, but I heard many recommendations of it for production. Either investigate deeply why currently the table is not created or go with flyway.

covert hawk
lapis umbraBOT
covert hawk
smoky hemlock
#

You're welcome.

lapis umbraBOT
#

πŸ’€ Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

covert hawk
#

one more question, i have deployed my backend on render, handled db on aiven. So whenever i am solving error, Which error should i solve, like error in render's log,aiven's log or in sts's log becuase all logs are giving different errors.

mint night
#

Well if you get an error in STS/locally, you shouldn't deploy it at all

#

and if an error occurs in production, you should fix that as well

covert hawk
#

Before deployment I was not getting any error in devlopment and my project was running fine. Now both the places I am getting errors.

mint night
#

maybe both are actually the same problem but different errors

#

but you should ensure both are fixed

charred nymph
mint night
#

but to be honest, are you sure you need a complete built JAR?

#

Do exploded files/the compiled class files not work?

covert hawk
mint night
mint night
#

Well your tables don't have primary keys

covert hawk
#

why is this happening? i mean i have added @Id annotation for the user,twit and like's IDs. other tables are made from mapping. Then Why is primary keys not being created?

mint night
#

Are you still using Hibernate DDL generation?

covert hawk
#

yes

mint night
#

Can you show the entities?

covert hawk
#

yes wait i am sending.

mint night
#

Do you have a schema.sql?

covert hawk
#

what is that can you explain?

mint night
#

oh so itΓ„s a User <--> User relation?

covert hawk
covert hawk
mint night
#

Can you try using two 1:n relations with another entity

#

but before that, check whether you have a schema.sql file

covert hawk
#

No i don't have a schema.sql file.

#

after changes you told.

#

2025-01-17T23:07:12.091+05:30 DEBUG 95968 --- [Connect] [ restartedMain] org.hibernate.SQL  :
alter table user_followers
add constraint FK6rk047eulefv05mknxaea9qmb
foreign key (followings_id)
references user (id)
Hibernate:
alter table user_followers
add constraint FK6rk047eulefv05mknxaea9qmb
foreign key (followings_id)
references user (id)
2025-01-17T23:07:12.162+05:30  WARN 95968 --- [Connect] [ restartedMain] o.h.t.s.i.ExceptionHandlerLoggedImpl  : GenerationTarget encountered exception accepting command : Error executing DDL "
alter table user_followers
add constraint FK6rk047eulefv05mknxaea9qmb
foreign key (followings_id)
references user (id)" via JDBC [Table 'defaultdb.user_followers' doesn't exist]
in previous code. user_followers..etc is not gettiing created only.

mint night
#

Can you show the entities for that?

covert hawk
#

The entities I sent you are only giving this exception.

mint night
covert hawk
mint night
#

Can you show the edited code?

lapis umbraBOT
#

πŸ’€ Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

covert hawk
mint night
#

you could also try adding targetEntty=User.class to the ManyToMany

mint night
covert hawk
# mint night but you probably need to do that

For that won't I need a particular follower and following class for writting vice versa onetomany and manytoone relation? That I don't have as I am making the table from user class itself.

mint night
#

so

@Entity
public class User {
  //...
  @OneToMany(mappedBy="followedBy")
  private List<Follow> follows;
  @OneToMany(mappedBy="followed")
  private List<Follow> followedBy;
  //...
}
@Entity
public class Follow{
  @Id
  @ManyToOne
  private User followedBy;
  @Id
  @ManyToOne
  private User followed;
  //...
}
#

like that

covert hawk
#

yes letme try.

#

@Id
@ManyToOne
private User followedBy;
@Id
@ManyToOne
private User followed; should i give primary key to both variables?

mint night
#

In the Follow class, yes

#

or alternatively you could also use a distinct id

covert hawk
#

@ManyToOne
@JoinColumn(name = "follower_id")
private Member follower;

@ManyToOne
@JoinColumn(name = "following_id")
private Member following;

in here in joincolum's name i have to give "user"?

mint night
#

?

#

you just make two 1:n relations there

iron meadow
#

in many to one you dont need to specify by what its mapped

covert hawk
#

token is coming null and db exception

iron meadow
#

probably because you dont use @generatedvalue annotation

#

so id is null

#

java.sql.SQLException: Field 'id' doesn't have a default value

#

try something like this on the id field

#
@GeneratedValue(strategy = GenerationType.IDENTITY)
#

oops

#

yea try that

mint night
#

Can you show the DDL from the actual database?

iron meadow
#

or no

mint night
#

if you are generating it

iron meadow
#

maybe it throws that error cuz its an object value

#

in the entity

#

instead of primitive

mint night
#

?

iron meadow
#

he has

#
private Long id;
mint night
#

that's exactly what I said is right

#

Long --> wrapper for long

iron meadow
#

yea

#

interesting then

#

wouldnt that solve the problem btw

#

for the error at least

#

id would get a default value

covert hawk
#

What do I do?

iron meadow
#

it technically shouldnt help but worth to try ig

covert hawk
#

Ok let me try

covert hawk
iron meadow
#

idk ask daniel

mint night
fallen hornetBOT
#

Can you show the DDL from the actual database?

covert hawk
#

-----------------------------------------+
| user | CREATE TABLE user (
login_with_google bit(1) NOT NULL,
req_user bit(1) NOT NULL,
status bit(1) DEFAULT NULL,
end_at datetime(6) DEFAULT NULL,
id bigint NOT NULL,
started_at datetime(6) DEFAULT NULL,
background_image varchar(255) DEFAULT NULL,
bio varchar(255) DEFAULT NULL,
birth_date varchar(255) DEFAULT NULL,
email varchar(255) DEFAULT NULL,
full_name varchar(255) DEFAULT NULL,
image varchar(255) DEFAULT NULL,
location varchar(255) DEFAULT NULL,
mobile varchar(255) DEFAULT NULL,
password varchar(255) DEFAULT NULL,
plan_type varchar(255) DEFAULT NULL,
website varchar(255) DEFAULT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+---

#

Twit table:
| twit | CREATE TABLE twit (
is_reply bit(1) NOT NULL,
is_twit bit(1) NOT NULL,
created_at datetime(6) DEFAULT NULL,
id bigint NOT NULL,
reply_for_id bigint DEFAULT NULL,
user_id bigint DEFAULT NULL,
content varchar(255) DEFAULT NULL,
image varchar(255) DEFAULT NULL,
video varchar(255) DEFAULT NULL,
total_likes int NOT NULL,
total_replies int NOT NULL,
total_retweets int NOT NULL,
PRIMARY KEY (id),
KEY FKcuglcrx19c9w9fduo9b74d7sr (reply_for_id),
KEY FKcupncc69r8ftdj6tpn96fcalc (user_id),
CONSTRAINT FKcuglcrx19c9w9fduo9b74d7sr FOREIGN KEY (reply_for_id) REFERENCES twit (id),
CONSTRAINT FKcupncc69r8ftdj6tpn96fcalc FOREIGN KEY (user_id) REFERENCES user (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |

#

Likes table:
---------------+
| likes | CREATE TABLE likes (
id bigint NOT NULL,
twit_id bigint DEFAULT NULL,
user_id bigint DEFAULT NULL,
PRIMARY KEY (id),
KEY FKoyol2981ncfimsdv6r5xske5t (twit_id),
KEY FKi2wo4dyk4rok7v4kak8sgkwx0 (user_id),
CONSTRAINT FKi2wo4dyk4rok7v4kak8sgkwx0 FOREIGN KEY (user_id) REFERENCES user (id),
CONSTRAINT FKoyol2981ncfimsdv6r5xske5t FOREIGN KEY (twit_id) REFERENCES twit (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |

lapis umbraBOT
# covert hawk -----------------------------------------+ | user | CREATE TABLE `user` ( `lo...
-----------------------------------------+
| user  | CREATE TABLE user (
  login_with_google bit(1) NOT NULL,
  req_user bit(1) NOT NULL,
  status bit(1) DEFAULT NULL,
  end_at datetime(6) DEFAULT NULL,
  id bigint NOT NULL,
  started_at datetime(6) DEFAULT NULL,
  background_image varchar(255) DEFAULT NULL,
  bio varchar(255) DEFAULT NULL,
  birth_date varchar(255) DEFAULT NULL,
  email varchar(255) DEFAULT NULL,
  full_name varchar(255) DEFAULT NULL,
  image varchar(255) DEFAULT NULL,
  location varchar(255) DEFAULT NULL,
  mobile varchar(255) DEFAULT NULL,
  password varchar(255) DEFAULT NULL,
  plan_type varchar(255) DEFAULT NULL,
  website varchar(255) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+---
lapis umbraBOT
# covert hawk Twit table: | twit | CREATE TABLE `twit` ( `is_reply` bit(1) NOT NULL, `is_...
Twit table:
| twit  | CREATE TABLE twit (
  is_reply bit(1) NOT NULL,
  is_twit bit(1) NOT NULL,
  created_at datetime(6) DEFAULT NULL,
  id bigint NOT NULL,
  reply_for_id bigint DEFAULT NULL,
  user_id bigint DEFAULT NULL,
  content varchar(255) DEFAULT NULL,
  image varchar(255) DEFAULT NULL,
  video varchar(255) DEFAULT NULL,
  total_likes int NOT NULL,
  total_replies int NOT NULL,
  total_retweets int NOT NULL,
  PRIMARY KEY (id),
  KEY FKcuglcrx19c9w9fduo9b74d7sr (reply_for_id),
  KEY FKcupncc69r8ftdj6tpn96fcalc (user_id),
  CONSTRAINT FKcuglcrx19c9w9fduo9b74d7sr FOREIGN KEY (reply_for_id) REFERENCES twit (id),
  CONSTRAINT FKcupncc69r8ftdj6tpn96fcalc FOREIGN KEY (user_id) REFERENCES user (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
lapis umbraBOT
# covert hawk Likes table: ---------------+ | likes | CREATE TABLE `likes` ( `id` bigint NOT...
Likes table:
---------------+
| likes | CREATE TABLE likes (
  id bigint NOT NULL,
  twit_id bigint DEFAULT NULL,
  user_id bigint DEFAULT NULL,
  PRIMARY KEY (id),
  KEY FKoyol2981ncfimsdv6r5xske5t (twit_id),
  KEY FKi2wo4dyk4rok7v4kak8sgkwx0 (user_id),
  CONSTRAINT FKi2wo4dyk4rok7v4kak8sgkwx0 FOREIGN KEY (user_id) REFERENCES user (id),
  CONSTRAINT FKoyol2981ncfimsdv6r5xske5t FOREIGN KEY (twit_id) REFERENCES twit (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
mint night
#

You are using GenerationType.IDENTITY so I think you should have AUTOINCREMENT configured for the table

#

Do you have that locally?

covert hawk
# mint night Do you have that locally?

Ya I had that locally, I even tried deploying with AUTO but I am facing same issue. also the ddl which I provided is of local db. Did you ask for the ddl of the db of production server?

mint night
#

you did say the error would only occur in production, right?

lapis umbraBOT
#

πŸ’€ Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

covert hawk
# mint night yes, I meant the DDL of the production server

Apologies, I thought that you are asking of local server as you wrote actual db. Here i am sending ddl of production server db. Also in production server only 3 tables are being made, wherein local server total of 11 tables were made.

#

User:
CREATE TABLE "user" (
"id" bigint NOT NULL,
"background_image" varchar(255) DEFAULT NULL,
"bio" varchar(255) DEFAULT NULL,
"birth_date" varchar(255) DEFAULT NULL,
"email" varchar(255) DEFAULT NULL,
"full_name" varchar(255) DEFAULT NULL,
"image" varchar(255) DEFAULT NULL,
"location" varchar(255) DEFAULT NULL,
"login_with_google" bit(1) NOT NULL,
"mobile" varchar(255) DEFAULT NULL,
"password" varchar(255) DEFAULT NULL,
"req_user" bit(1) NOT NULL,
"end_at" datetime(6) DEFAULT NULL,
"plan_type" varchar(255) DEFAULT NULL,
"started_at" datetime(6) DEFAULT NULL,
"status" bit(1) DEFAULT NULL,
"website" varchar(255) DEFAULT NULL,
PRIMARY KEY ("id")
)
Twit:
CREATE TABLE "twit" (
"id" bigint NOT NULL,
"content" varchar(255) DEFAULT NULL,
"created_at" datetime(6) DEFAULT NULL,
"image" varchar(255) DEFAULT NULL,
"is_reply" bit(1) NOT NULL,
"is_twit" bit(1) NOT NULL,
"total_likes" int NOT NULL,
"total_replies" int NOT NULL,
"total_retweets" int NOT NULL,
"video" varchar(255) DEFAULT NULL,
"reply_for_id" bigint DEFAULT NULL,
"user_id" bigint DEFAULT NULL,
PRIMARY KEY ("id"),
KEY "FKcuglcrx19c9w9fduo9b74d7sr" ("reply_for_id"),
KEY "FKcupncc69r8ftdj6tpn96fcalc" ("user_id"),
CONSTRAINT "FKcuglcrx19c9w9fduo9b74d7sr" FOREIGN KEY ("reply_for_id") REFERENCES "twit" ("id"),
CONSTRAINT "FKcupncc69r8ftdj6tpn96fcalc" FOREIGN KEY ("user_id") REFERENCES "user" ("id")
)
likes:
CREATE TABLE "likes" (
"id" bigint NOT NULL,
"twit_id" bigint DEFAULT NULL,
"user_id" bigint DEFAULT NULL,
PRIMARY KEY ("id"),
KEY "FKoyol2981ncfimsdv6r5xske5t" ("twit_id"),
KEY "FKi2wo4dyk4rok7v4kak8sgkwx0" ("user_id"),
CONSTRAINT "FKi2wo4dyk4rok7v4kak8sgkwx0" FOREIGN KEY ("user_id") REFERENCES "user" ("id"),
CONSTRAINT "FKoyol2981ncfimsdv6r5xske5t" FOREIGN KEY ("twit_id") REFERENCES "twit" ("id")
)

mint night
#

And your existing code really works locally/in development?

mint night
covert hawk
#

will i have to declare inheritance at class level?

mint night
covert hawk
mint night
#

you don't need to declare inheritance if you don't use it

#

but yes, if you make use of it, you need to declare it with the corresponding annotations

covert hawk
#

ok rn i am again trying out with AUTO then i willl go with inheritance

covert hawk
fallen hornetBOT
#

package hibtest.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;

@Entity
@Inheritance(strategy = InheritanceType.JOINED) ```java

public class Mensagem {
protected Long id;

protected Mensagem() { }

@Id
@GeneratedValue
public Long getId() {
    return id;

}

public Mensagem setId(Long id) {
    this.id = id;
    return this;
}

} ```

This message has been formatted automatically. You can disable this using /preferences.

mint night
#

you should only use @Inheritance if you actually have entities extending each other which makes quite a bit of stuff more complicate and less likely to work

covert hawk
#

ohh understood! then what do i do If AUTO doesn't work out?

mint night
mint night
#

Do you know what CORS is?

covert hawk
#

yes it is for connecting the backend and frontend. do you need to see the cors file?

mint night
#

check the CORS headers

covert hawk
#

Yeah

mint night
#

in the browser devtools

covert hawk
#

request:
accept:
application/json, text/plain, /
content-type:
application/json
referer:
https://connect-2cgoq5uvw-harsh-vyas-projects-049c37b9.vercel.app/
sec-ch-ua:
"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"
sec-ch-ua-mobile:
?1
sec-ch-ua-platform:
"Android"
user-agent:
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36

#

Request URL:
https://connect-backend-umbj.onrender.com/auth/signup
Request Method:
OPTIONS
Status Code:
403 Forbidden
Remote Address:
216.24.57.252:443
Referrer Policy:
strict-origin-when-cross-origin
alt-svc:
h3=":443"; ma=86400
cache-control:
no-cache, no-store, max-age=0, must-revalidate
cf-cache-status:
DYNAMIC
cf-ray:
904e4337fb650333-AMD
date:
Mon, 20 Jan 2025 10:08:19 GMT
expires:
0
pragma:
no-cache
priority:
u=1,i
rndr-id:
4b37cd99-f872-4052
server:
cloudflare
server-timing:
cfExtPri
strict-transport-security:
max-age=31536000 ; includeSubDomains
vary:
Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Accept-Encoding
x-content-type-options:
nosniff
x-frame-options:
DENY
x-render-origin-server:
Render
x-xss-protection:
0
:authority:
connect-backend-umbj.onrender.com
:method:
OPTIONS
:path:
/auth/signup
:scheme:
https
accept:
/
accept-encoding:
gzip, deflate, br, zstd
accept-language:
en-US,en;q=0.9
access-control-request-headers:
content-type
access-control-request-method:
POST
origin:
https://connect-2cgoq5uvw-harsh-vyas-projects-049c37b9.vercel.app
priority:
u=1, i
referer:
https://connect-2cgoq5uvw-harsh-vyas-projects-049c37b9.vercel.app/
sec-fetch-dest:
empty
sec-fetch-mode:
cors
sec-fetch-site:
cross-site
user-agent:
Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36

#

this is given in the header

mint night
#

What's the response that failed/caused the issue?

covert hawk
mint night
#

I am asking for the response in the devtools

mint night
#

yeah it seems like it

covert hawk
#

yes that is the response

mint night
#

the server is just not sending the CORS headers

#

I think

covert hawk
#

ya maybe because i had given the wrong vercel domain. i have changed it lets see now.

covert hawk
#

Not working out. Still having the same issue.

mint night
#

Can you show the CORS config?

fallen hornetBOT
#

@Bean ```java

public CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration configuration = new CorsConfiguration();

    // Allow requests from the React frontend

// configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000"));
configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
configuration.setAllowedOrigins(Arrays.asList("https://connect-2cgoq5uvw-harsh-vyas-projects-049c37b9.vercel.app", "http://localhost:3000"));
configuration.setAllowCredentials(true);

    // Allow common headers including Authorization
    configuration.setAllowedHeaders(Arrays.asList(
        "Authorization",
        "Content-Type",
        "Accept",
        "X-Requested-With",
        "Origin",
        "Access-Control-Request-Method",
        "Access-Control-Request-Headers"
    ));
    configuration.setExposedHeaders(Arrays.asList("Authorization"));
    configuration.setMaxAge(3600L); // Cache preflight requests for 1 hour

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);
    return source;
} ```

This message has been formatted automatically. You can disable this using /preferences.

mint night
#

and you are still getting the exact same CORS error with the exact same URL in the browser devtools?

#

Can you access the site with curl -i?

covert hawk
#

ok so now i changed the domains to previous ones and cors error is removed and the same old error of id doesn't have default.. is coming. when i accessed the site with curl -i i got output:
C:\Users\harsh>curl -i https://connect-chi-gules.vercel.app/
HTTP/1.1 200 OK
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Age: 22955
Cache-Control: public, max-age=0, must-revalidate
Content-Disposition: inline
Content-Length: 644
Content-Type: text/html; charset=utf-8
Date: Mon, 20 Jan 2025 13:07:53 GMT
Etag: "9c3b7f0a6cd316545fb1afbb895d844e"
Last-Modified: Mon, 20 Jan 2025 06:45:18 GMT
Server: Vercel
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Vercel-Cache: HIT
X-Vercel-Id: bom1::8pglv-1737378473717-261775c29117

<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><script defer="defer" src="/static/js/main.33661283.js"></script><link href="/static/css/main.0af02c3b.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

mint night
#

I meant accessing the backend with curl to get more information about the CORS error

#

So you still get the SQL error in production but not in dev?

mint night
#

if the CORS error no longer happens, it's fine

#

For the SQL error, try adding AUTO_INCREMENT to the id column

covert hawk
#

ok

covert hawk
#

State: 42S02
2025-01-20T13:54:20.838Z ERROR 1 --- [Connect] [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : Table 'defaultdb.user_seq' doesn't exist
2025-01-20T13:54:21.740Z ERROR 1 --- [Connect] [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: error performing isolated work [Table 'defaultdb.user_seq' doesn't exist] [n/a]; SQL [n/a]] with root cause

#

added auto inc in user table's id so getting this exception on render

#

token:null
2025-01-20T13:54:16.343Z DEBUG 1 --- [Connect] [nio-8080-exec-3] org.hibernate.SQL :
select
u1_0.id,
u1_0.background_image,
u1_0.bio,
u1_0.birth_date,
u1_0.email,
u1_0.full_name,
u1_0.image,
u1_0.location,
u1_0.login_with_google,
u1_0.mobile,
u1_0.password,
u1_0.req_user,
u1_0.end_at,
u1_0.plan_type,
u1_0.started_at,
u1_0.status,
u1_0.website
from
user u1_0
where
u1_0.email=?
Hibernate:
select
u1_0.id,
u1_0.background_image,
u1_0.bio,
u1_0.birth_date,
u1_0.email,
u1_0.full_name,
u1_0.image,
u1_0.location,
u1_0.login_with_google,
u1_0.mobile,
u1_0.password,
u1_0.req_user,
u1_0.end_at,
u1_0.plan_type,
u1_0.started_at,
u1_0.status,
u1_0.website
from
user u1_0
where
u1_0.email=?
2025-01-20T13:54:20.128Z DEBUG 1 --- [Connect] [nio-8080-exec-3] org.hibernate.SQL :
select
next_val as id_val
from
user_seq for update
Hibernate:
select
next_val as id_val
from
user_seq for update
2025-01-20T13:54:20.445Z ERROR 1 --- [Connect] [nio-8080-exec-3] o.hibernate.id.enhanced.TableStructure : could not read a hi value
also this

mint night
#

oh you still have GenerationType.AUTO

#

You'd need GenerationType.IDENTITY if you want to use AUTO_INCREMENT

covert hawk
#

Ohh ok let me try.

covert hawk
#

ok so some positive news!!!! that token is being generated and data is getting inserted in db but user_follower(the extra table which was created through mapping) is not getting created and likewise all the other extra tables will also throw the same errors ig.

#

2025-01-20T17:37:31.900Z ERROR 1 --- [Connect] [nio-8080-exec-3] o.h.engine.jdbc.spi.SqlExceptionHelper : Table 'defaultdb.user_followers' doesn't exist
2025-01-20T17:37:31.938Z ERROR 1 --- [Connect] [nio-8080-exec-3] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL [select f1_0.user_id,f1_1.id,f1_1.background_image,f1_1.bio,f1_1.birth_date,f1_1.email,f1_1.full_name,f1_1.image,f1_1.location,f1_1.login_with_google,f1_1.mobile,f1_1.password,f1_1.req_user,f1_1.end_at,f1_1.plan_type,f1_1.started_at,f1_1.status,f1_1.website from user_followers f1_0 join user f1_1 on f1_1.id=f1_0.followers_id where f1_0.user_id=?] [Table 'defaultdb.user_followers' doesn't exist] [n/a]] with root cause
java.sql.SQLSyntaxErrorException: Table 'defaultdb.user_followers' doesn't exist

mint night
#

well the table for the relation is missing

iron meadow
#

show the user followers class

covert hawk
covert hawk
mint night
#

In your User entity, you have a user_followers relation

#

and for that relation, you need a table

iron meadow
#

show the user class then

fallen hornetBOT
mint night
#

see the followers field

#

which references a user_followers table

covert hawk
#

yes understood but what change do i need to make?

iron meadow
#

yea

#

so

#

why dont you use some other class

#

to keep the followers

mint night
iron meadow
#

tbh i would just make another class named UserFollows

#

and keep the follows there

#

way easier

#

didnt u suggest that before terminator daniel

mint night
iron meadow
#

yea but

mint night
#

like idk whether JPA supports self references

iron meadow
#

in that case the relation will be different

#

it will be one to many

#

from user to the user follows

#

class

mint night
#
CREATE TABLE `user_followers` (
  `user_id` bigint NOT NULL REFERENCES `user` (`id`),
  `follower_id` bigint NOT NULL REFERENCES `user` (`id`),
  PRIMARY KEY (`user_id`, `follower_id`)
);

something like that

iron meadow
covert hawk
#

yes sir creating new table.

covert hawk
iron meadow
#

well

#

up to you

covert hawk
# iron meadow up to you

i am trying this for now, if nothing happens that is the last option left for me or will switch to flyaway as suggested by daniel sir.

#

Also @mint night sir do i also need to make twit's and like's id's column auto increment na?

mint night
mint night
mint night
#

it would in principle even be possible without changing any classes

#

like

@OneToMany(mappedBy="follower")
private List<UserFollow> outgoingFollows = new ArrayList<>();
@OneToMany(mappedBy="followed")
private List<UserFollow> incomingFollows = new ArrayList<>();


@Transient
public List<User> getFollowers(){
  return incomingFollows
    .stream()
    .map(UserFollow::getFollower)
    .toList();
}
@Transient
public List<User> getFollowings(){
  return outgoingFollows
    .stream()
    .map(UserFollow::getFollowing)
    .toList();
}
#

though you would still need to change your repositories

mint night
covert hawk
#

Ohk applying the changes

mint night
mint night
iron meadow
#

i would say just make the class

#

code gonna look better

mint night
#

btw don't forget: If you didn't test it in development or it didn't work there, there's no point in deploying to production

iron meadow
#

and loose coupling

mint night
#

it's just an additional indirection but it's still coupled in pretty much the same way (just using the additional indirection)

lapis umbraBOT
#

πŸ’€ Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

covert hawk
#

now i am facing another issue after adding auto increment,that when i open the domain it is directly requesting for profile and hitting the /home url which is supposed to hit after the login/signup. also token is which i said was generating is getting generated everytime when i open the domain with the same credentials i entered previously.

mint night
#

Can you show your security configuration?

#

Did you configure any filters?

covert hawk
mint night
#

Can you show your JwtTokenValidator?

covert hawk
#

yes

mint night
#

When generates the token and when exactly do you want it to be generated?

covert hawk
#

When I singup or signin

iron meadow
#

question aside

#

seems like its gonna be one of the longest threads

#

😱

covert hawk
#

Nope i don't think so, yesterday I Saw a thread with 312 messages

iron meadow
#

oh yea true

mint night
fallen hornetBOT
#

JwtProvider:
package com.Config;

import java.util.Date;
import static java.lang.System.currentTimeMillis;
import java.util.stream.Collectors;

import javax.crypto.SecretKey;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

@Service
public class JwtProvider ```java

{
SecretKey key=Keys.hmacShaKeyFor(jwtConstant.SECRET_KEY.getBytes());
public String generateToken(Authentication auth)
{
// String authorities = auth.getAuthorities().stream()
// .map(GrantedAuthority::getAuthority)
// .collect(Collectors.joining(","));

     String authorities= auth.getAuthorities().toString();
             
             
             

     
    return Jwts.builder()
            .setIssuedAt(new Date())
            .setExpiration(new Date(System.currentTimeMillis()+86400000))
            .claim("email",auth.getName())
            .claim("authorities", authorities)
            .signWith(key)
            .compact();
}
public String getEmailFromToken(String jwt)
{
    jwt=jwt.substring(7);
    Claims claims=Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jwt).getBody();
    String email=String.valueOf(claims.get("email"));
    return email;
}

} ```

This message has been formatted automatically. You can disable this using /preferences.

lapis umbraBOT
# fallen hornet JwtProvider: package com.Config; import java.util.Date; import static java.lang...
JwtProvider:
package com.Config;

import java.util.Date;
import static java.lang.System.currentTimeMillis;
import java.util.stream.Collectors;

import javax.crypto.SecretKey;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

@Service
public class JwtProvider  
{
    SecretKey key=Keys.hmacShaKeyFor(jwtConstant.SECRET_KEY.getBytes());
    public String generateToken(Authentication auth)
    {
//         String authorities = auth.getAuthorities().stream()
//                                 .map(GrantedAuthority::getAuthority)
//                                 .collect(Collectors.joining(","));
                 
         String authorities= auth.getAuthorities().toString();
                 
                 
                 

         
        return Jwts.builder()
                .setIssuedAt(new Date())
                .setExpiration(new Date(System.currentTimeMillis()+86400000))
                .claim("email",auth.getName())
                .claim("authorities", authorities)
                .signWith(key)
                .compact();
    }
    public String getEmailFromToken(String jwt)
    {
        jwt=jwt.substring(7);
        Claims claims=Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jwt).getBody();
        String email=String.valueOf(claims.get("email"));
        return email;
    }


} 
mint night
#

what calls that?

covert hawk
mint night
#

So what exact request are you making and how are you authenticating that request such that it generates a token that you don't want?

covert hawk
#

ok so done and dusted!!!! the problem was the jwt was not getting removed from local storage. so i removed it and the problem with the db was "sql_require_primary_key" this term in aiven doesn't allow a table without a primary key to be made.so that is why it was giving me such errors i disabled that button and deleted the jwt from local storage and my problem got solved.

lapis umbraBOT
covert hawk
#

Also big thank you to @mint night , @iron meadow , @smoky hemlock and @charred nymph for replying and helping my problem get solved. Really means a lot. A big Thank you!!!

iron meadow
#

woooohooooooooooo